string byte dump

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jammer

    #1

    string byte dump

    Does anyone that knows python want to write me a byte dump for strings? :-)

    I am trying to modify a plugin (that someone else wrote) that uses
    interprocess communication.
    It works on strings without special characters but it fails on other
    stings like "Björk".

    It calls decode('utf8') but I guess the strings are not utf8 so I need
    to find out what is being input.
  • Rob Wolfe

    #2
    Re: string byte dump

    Jammer <ask.me@mail.co mwrites:
    Does anyone that knows python want to write me a byte dump for strings? :-)
    >
    I am trying to modify a plugin (that someone else wrote) that uses
    interprocess communication.
    It works on strings without special characters but it fails on other
    stings like "Björk".
    >
    It calls decode('utf8') but I guess the strings are not utf8 so I need
    to find out what is being input.
    Try this:
    >>"abc".encode( "hex")
    '616263'

    --
    HTH,
    Rob

    Comment

    • Jammer

      #3
      Re: string byte dump

      Rob Wolfe wrote:
      Jammer <ask.me@mail.co mwrites:
      >
      >Does anyone that knows python want to write me a byte dump for strings? :-)
      >>
      >I am trying to modify a plugin (that someone else wrote) that uses
      >interprocess communication.
      >It works on strings without special characters but it fails on other
      >stings like "Björk".
      >>
      >It calls decode('utf8') but I guess the strings are not utf8 so I need
      >to find out what is being input.
      >
      Try this:
      >
      >>>"abc".encode ("hex")
      '616263'
      >
      Awesome, thanks.

      Comment

      • John Machin

        #4
        Re: string byte dump



        On Jan 29, 4:57 am, Jammer <ask...@mail.co mwrote:
        Does anyone that knows python want to write me a byte dump for strings? :-)
        >
        I am trying to modify a plugin (that someone else wrote) that uses
        interprocess communication.
        It works on strings without special characters but it fails on other
        stings like "Björk".
        >
        It calls decode('utf8') but I guess the strings are not utf8 so I need
        to find out what is being input.
        Try the repr() built-in function. Any byte not in printable ASCII will
        be displayed in hex.

        | >>foo = "\xfforick"
        | >>foou = unicode(foo, 'latin1')
        | >>foo8 = foou.encode('ut f8')
        | >>print repr(foo), repr(foou), repr(foo8)
        | '\xfforick' u'\xfforick' '\xc3\xbforick'


        Comment

        Working...