By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,941 Members | 1,753 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,941 IT Pros & Developers. It's quick & easy.

Showing native 8-bit strings in Python interpreter

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.