On Oct 24, 2006, at 12:41 PM, sophana wrote:
Hartmut Goebel a écrit :This is indeed the typical very annoying feature I was talking about. InJorge Godoy schrieb:Change the order.s = u'olá' s += 'mundo' su'ol\xe1mundo's = u'leite com ' s += 'café'Traceback (most recent call last): File "<stdin>", line 1, in ?UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position3: ordinal not in range(128)web application, these strings with unicode inside come from the web requests. Why isn't the string class simply replaced by the unicode class? Why 2 classes?
There are currently two classes because early versions of python didn't know about Unicode. In Python 3.x strings will be unicode and there will be a seperate type for dealing with 8-bit data.
Ok, but why is the right string encoded into ascii and not into the sameThis is correct, since you tell python to add a Unicode-String to an Asc-String: s += 'café' is the same as s = s + 'café'encoding as the left unicode string? Isn't the += operator an unicode method?
Unicode strings don't have an encoding. 8-bit strings (the str type) do have an encoding, but that encoding is implied by the environment and is not an attribute of the string. That's why python uses one (more or less arbitrary) encoding for implicit conversions. If you know better (because the protocol you use specifies that text is in UTF-8 format, or you know your string constants are encoded in koi-8, ...) you should do an explicit conversion instead of relying on the default conversion.
Ronald
smime.p7s
Description: S/MIME cryptographic signature
------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________ sqlobject-discuss mailing list sqlobject-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss