nonascii symbols

Ricardo Bugalho ricardo.b at
Sat Jul 10 14:54:01 CEST 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 

# -*- 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)


More information about the Python-list mailing list