unicode woes

Martin v. Löwis loewis at informatik.hu-berlin.de
Thu Sep 26 07:04:44 EDT 2002

Ulli Stein <mennosimons at gmx.net> writes:

> Or how would you do this (nonsense string):
> str = str + "blaäö" + str[:5] + "ßüä"
> Would you write then:
> str = str + unicode("blaäö") + str[:5] + unicode("ßüä")?

If you want to use Unicode in source code, and you want to use
non-English text: yes, you have to define a helper function, e.g.

def uni(x):
  return unicode(x, "iso-8859-1")

In this case, the system encoding might be incorrect; Python cannot
know what encoding you use in your source code: If you move your
source code from one machine to another, the system encoding may
change, but your source code won't.

If you want to write internationalized code, I recommend to avoid
using non-English string literals. Instead, use English text, and
translate this at run-time using message catalogs (e.g. gettext).

> And what about the "encode" variable in site.py: If another Python 
> application running in parallel to our application changes the encode 
> string, will it affect our app? Or has every application its own encode 
> string?

If you keep your sitecustomize.py in a location that is private to
your application, there is a good chance that it won't interfere with
another application.


More information about the Python-list mailing list