Python strings outside the 128 range

Diez B. Roggisch deets at nospam.web.de
Fri Jul 14 09:14:02 EDT 2006


Gerhard Fiedler schrieb:
> On 2006-07-13 12:04:58, Richard Brodie wrote:
> 
>>>  s = "é"
>>>  print s
> 
>>> Is there a standard way to do this?
>> Use Unicode strings, with an explicit encoding.  Say no to ISO-8859-1 centrism.
>> See: http://www.amk.ca/python/howto/unicode particularly the
>> "Unicode Literals in Python Source Code" section.
> 
> So ...
> 
>   # coding: utf-8
>   s = u'é'
>   print s
> 
> (Of course stored with an editor that writes the file in utf-8 encoding.)
> 
> Is this the proper way?
> 
> Will print take care of encoding translation according to the encoding used
> in the target console?

Of course not. AFAIK there is no way figuring out which encoding the 
target console supports. The best you can do is to offer an option that 
allwos selection of the output encoding.

And when using print, don't forget to wrap sys.stdout with a 
codecs.EncodedFile to properly convert the unicode strings.


Diez



More information about the Python-list mailing list