Ronald Oussoren a écrit :
This is indeed the typical very annoying feature I was talking about. In
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.
Cool!

Ok, but why is the right string encoded into ascii and not into the same
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.
Ok, I understand better.
Sorry for being off topic, but does any one knows how to change the default encoding conversion?
Tried to use LANG=en_US.UTF-8 : this does not work.
The encoding header in a python file doesn't work either.
Oops, never mind. I found some results on google: http://www.diveintopython.org/xml_processing/unicode.html

Example 9.15. sitecustomize.py

# sitecustomize.py                   1
# this file can be anywhere in your Python path,
# but it usually goes in ${pythondir}/lib/site-packages/
import sys
sys.setdefaultencoding('iso-8859-1') 2
1 sitecustomize.py is a special script; Python will try to import it on startup, so any code in it will be run automatically. As the comment mentions, it can go anywhere (as long as import can find it), but it usually goes in the site-packages directory within your Python lib directory.

Will try that. I don't want to change the system behaviour. I hope it will work with webware.

Too bad I didn't find it earlier. I had many many troubles finding the numerous places in my code where such concatenation was made, adding unicode conversion manually. Many bugs in production because of that after I translated my website.


-------------------------------------------------------------------------
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss

Reply via email to