string byte dump

J

Jammer

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.
 
R

Rob Wolfe

Jammer said:
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:
'616263'
 
J

John Machin

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'
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top