nonascii symbols
Ricardo Bugalho
ricardo.b at zmail.pt
Sat Jul 10 08:54:01 EDT 2004
On Sat, 10 Jul 2004 05:33:52 +0000, Elaine Jackson wrote:
> What's the trick for using nonascii symbols in string literals?
Declare the file encoding in the 1st or second line do the file, like
this:
# -*- coding: utf-8 -*-
# Hello world, in portuguese.
print "Olá Mundo!"
However, this doesn't solve the problem of code portability over systems
with different chartsets.
To do that, I like using unicode string literals and locale.
# -*- coding: utf-8 -*-
import locale
country, coding = locale.getdefaultlocale()
str = u'Olá Mundo!'
print str.encode(coding)
--
Ricardo
More information about the Python-list
mailing list