[Tutor] Encoding
Giorgio
anothernetfellow at gmail.com
Fri Mar 5 14:56:37 CET 2010
>
>
>> 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.
>
>
>
Ok Dave, What i don't understand is why:
s = u"ciao è ciao" is converting a string to unicode, decoding it from the
specified encoding but
t = "ciao è ciao"
t = unicode(t)
That should do exactly the same instead of using the specified encoding
always assume that if i'm not telling the function what the encoding is, i'm
using ASCII.
Is this a bug?
Giorgio
--
--
AnotherNetFellow
Email: anothernetfellow at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100305/45cc3de7/attachment.html>
More information about the Tutor
mailing list