string byte dump

Discussion in 'Python' started by Jammer, Jan 28, 2007.

  1. Jammer

    Jammer Guest

    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.
    Jammer, Jan 28, 2007
    #1
    1. Advertising

  2. Jammer

    Rob Wolfe Guest

    Jammer <> writes:

    > 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
    Rob Wolfe, Jan 28, 2007
    #2
    1. Advertising

  3. Jammer

    Jammer Guest

    Rob Wolfe wrote:
    > Jammer <> writes:
    >
    >> 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.
    Jammer, Jan 28, 2007
    #3
  4. Jammer

    John Machin Guest

    On Jan 29, 4:57 am, Jammer <> wrote:
    > 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('utf8')
    | >>> print repr(foo), repr(foou), repr(foo8)
    | '\xfforick' u'\xfforick' '\xc3\xbforick'
    John Machin, Jan 28, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andreas
    Replies:
    1
    Views:
    843
    Jonathan Bromley
    May 4, 2004
  2. Peter
    Replies:
    3
    Views:
    725
    Michael Borgwardt
    Aug 5, 2004
  3. halfdog
    Replies:
    12
    Views:
    12,435
  4. jt
    Replies:
    3
    Views:
    921
    Keith Thompson
    May 23, 2005
  5. Polaris431
    Replies:
    8
    Views:
    753
    SM Ryan
    Dec 4, 2006
Loading...

Share This Page