[Grok-dev] Re: Understanding unicode

Philipp von Weitershausen philipp at weitershausen.de
Fri Aug 31 15:38:49 EDT 2007


Jan Ulrich Hasecke wrote:
> When I insert u'Paviankäfig' I get an unicode error.
> 
>  UnicodeEncodeError: 'ascii' codec can't encode characters in position 
> 7-8: ordinal not in range(128)

You've inserted a non-ASCII character in your Python source code. Python 
doesn't known which encoding this should be. The default encoding that 
it will open files with is 'ascii' which doesn't support any characters 
over byte 127. As Martijn pointed out, you'll have to explicitly tell it 
which encoding to use at the top of the file, e.g.::

   # -*- coding: utf-8 -*-
   x = u'Käfig'

Note that it's 'utf-8' (lower case), not 'UTF-8'.


-- 
http://worldcookery.com -- Professional Zope documentation and training


More information about the Grok-dev mailing list