Showing native 8-bit strings in Python interpreter
Diez B. Roggisch
deets at nospam.web.de
Thu Nov 8 06:19:09 EST 2007
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
More information about the Python-list
mailing list