editing in Unicode

Martin von Loewis loewis at informatik.hu-berlin.de
Fri Sep 8 16:43:03 EDT 2000


"Bertilo Wennergren" <bertilow at hem.passagen.se> writes:

> If I get this right the following simpler version ought to work:
> 
> msg=unicode("@#&")
> 
> Right? That I could live with.

You can certainly do

def _u(str):
  return unicode(str,"utf-8")

and then

msg = _u("@#&")

However, may I ask what unicode strings exactly you need in source
code?  If you have messages to display, it may be that you want to
support more than one language (BTW, which language are your messages in?).

For multi-language applications, I recommend the use of the gettext
module:

from gettext import ugettext as _

msg = _("hello")

That will, at run-time, retrieve the translation of "hello" into
Russian, German, whatever ... and return the translated string as a
Unicode object. For that to work, you need the pygettext and msgfmt
tools coming with Python 2.0.

Regards,
Martin




More information about the Python-list mailing list