[Tutor] Encoding

Dave Angel davea at ieee.org
Fri Mar 5 03:39:27 CET 2010



Giorgio wrote:
> 2010/3/4 spir <denis.spir at gmail.com>
>
> <snip>
> Ok,so you confirm that:
>
> s = u"ciao è ciao" will use the file specified encoding, and that
>
> t = "ciao è ciao"
> t = unicode(t)
>
> Will use, if not specified in the function, ASCII. It will ignore the
> encoding I specified on the top of the file. right?
>
>   
A literal  "u" string, and only such a (unicode) literal string, is 
affected by the encoding specification.  Once some bytes have been 
stored in a 8 bit string, the system does *not* keep track of where they 
came from, and any conversions then (even if they're on an adjacent 
line) will use the default decoder.  This is a logical example of what 
somebody said earlier on the thread -- decode any data to unicode as 
early as possible, and deal only with unicode strings in the program.  
Then, if necessary, encode them into whatever output form immediately 
before (or while) outputting them.


> Again, thankyou. I'm loving python and his community.
>
> Giorgio
>
>
>
>
>   


More information about the Tutor mailing list