472,101 Members | 1,427 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,101 software developers and data experts.

Showing native 8-bit strings in Python interpreter

I'm storing 8-bit characters from the 128-256 range in Python
strings. They are Windows CP1251 Russian characters. When looking at
those strings in the Python interpreter, they come up as codes inside
the string. How can I teach Python to show those 8-bit characters in
the native encoding of the terminal -- in the current locale -- where
the interpreter was started?

Cheers,
Alexy

Nov 8 '07 #1
1 1285
braver wrote:
I'm storing 8-bit characters from the 128-256 range in Python
strings. They are Windows CP1251 Russian characters. When looking at
those strings in the Python interpreter, they come up as codes inside
the string. How can I teach Python to show those 8-bit characters in
the native encoding of the terminal -- in the current locale -- where
the interpreter was started?
The python-interpreter will print them out using hex because it calls
repr(string) - to prevent any encoding-related troubles.

But printing them will meet your expectations. See below:

Python 2.5.1 (r251:54863, May 2 2007, 16:56:35)
>>s = 'äöüßÄÜ'
s
'\xc3\xa4\xc3\xb6\xc3\xbc\xc3\x9f\xc3\x84\xc3\x9c'
>>print s
äöüßÄÜ
>>>

Diez
Nov 8 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by David Kantowitz | last post: by
3 posts views Thread by Xavi Sam | last post: by
22 posts views Thread by Andy Chan | last post: by
9 posts views Thread by Herby | last post: by
8 posts views Thread by Gary Nastrasio | last post: by
2 posts views Thread by Bob Altman | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.