unicode mystery/problem

Petr Jakes petr at tpc.cz
Wed Sep 20 13:40:55 EDT 2006

I am using Python 2.4.3 on Fedora Core4 and  "Eric3" Python IDE
Below mentioned code works fine in the Eric3 environment. While trying
to start it from the command line, it returns:

Traceback (most recent call last):
  File "pokus_1.py", line 5, in ?
    print str(a)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xc1' in
position 6: ordinal not in range(128)

========== 8< =============
#!/usr/bin python
# -*- Encoding: utf_8 -*-

a= u'DISKOV\xc1 POLE'
print a
print str(a)
========== 8< =============

Even it looks strange, I have to use str(a) syntax even I know the "a"
variable is a string.
I am trying to use ChartDirector for Python (charts for Python) and the
method "layer.addDataSet()" needs above mentioned syntax otherwise it
returns an Error.

layer.addDataSet(data, colour, str(dataName))
Thanks for your comments

Petr Jakes

More information about the Python-list mailing list