On 11/8/05, stan8688 <[EMAIL PROTECTED]> wrote:
I cannot help with your core problem, but I wanted to raise a caution about your last thought here...
The sys.setdefaultencode is only meant to be used by Python when it is first starting up (that is documented and it is why you get an error when trying to use it). After that, it is removed from the sys namespace.
You do not want to be changing your system's default encoding, as tempting as it may be, because this will cause strange breakages in other modules: things you distribute might not work on other installations and vice-versa. Unfortunately Python is stuck with the choice of ascii for the default encoding for a while longer. This is annoying, I agree, because it means that we need to wrap a lot of strings in u'...', rather than just using, for example, utf-8 everywhere. But that is the price of compatibility.
Cheers,
Malcolm
Thank you for your responed fast, Adrain.
Yes, you are right, When i use:
s = u"中国"
d = categorylangs.Categorylang(categorylang = s.encode('utf-8'))
d.save()
It is ok! when i saw through DB. but. when I use
d = categorylangs.get_list(categorylang__contains = s.encode('utf-8'))
print d.
it does not show correct. !
I think MayBe is my sys encode is not correct? I saw
sys.getdefaultencoding is ascii
How can i change sys encode to 'utf-8'
When i use sys.setdefaultencode will error.
I cannot help with your core problem, but I wanted to raise a caution about your last thought here...
The sys.setdefaultencode is only meant to be used by Python when it is first starting up (that is documented and it is why you get an error when trying to use it). After that, it is removed from the sys namespace.
You do not want to be changing your system's default encoding, as tempting as it may be, because this will cause strange breakages in other modules: things you distribute might not work on other installations and vice-versa. Unfortunately Python is stuck with the choice of ascii for the default encoding for a while longer. This is annoying, I agree, because it means that we need to wrap a lot of strings in u'...', rather than just using, for example, utf-8 everywhere. But that is the price of compatibility.
Cheers,
Malcolm