Toby Dickenson kirjutas P, 03.11.2002 kell 01:15:
On Saturday 02 November 2002 1:48 am, Tino Wildenhain wrote:
if encoding != "ascii": sys.setdefaultencoding(encoding)
This implies modification of the installed code to change default behavior. I would consider this as bad. Why isnt a locales sensitive version the default?
That would make it difficult to write reliable portable Python code. It is a good thing that Python has predictable behaviour for things like (string+integer), a local-sensitive or user-sensitive default encoding would make (plain string+unicode string) unpredictable.
So the default encoding = 'ascii' is there to always force explicit conversion ?
Note that nothing else in Python depends on locales by default. Not even date formatting, for example.
Has python finally got a decent standard date module ?
However, there is lukyly another way to do it:
let us provide a sitecustomize.py module for zope. If its in the path, it has access to sys.setdefaultencoding
That still breaks Python libraries that assume this has not been changed.
This is a legitimate assumption made by these libraries; the same as assuming the behaviour of (string+integer).
Otoh it is quite weird to have a way to set default encoding that is inaccessible for users ;(
I use it that way (I set utf-8) and Zope unicodes and strings quite good.
Feel free to do that in your own zope, but this will never be a supported way of using Python. I think it is irresponsible to recommend this approach as if it was standard practice.
sitecustomize.py seems to be the recommended way of overriding the default charset , so why not recommend it as such? And UTF-8 as default encoding for unicode should become the supported way of using Python - computing is becoming universally available to all people, not just plain-ascii-speaking ones. ----------------------- Hannu