a question about unicode in python

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Tue Jun 12 12:28:54 EDT 2007


In <1181663182.251071.10540 at i13g2000prf.googlegroups.com>, hzqij wrote:

> i have a python source code test.py
> 
> # -*- coding: UTF-8 -*-
> 
> # s is a unicode string, include chinese
> s = u'张三'
> 
> then i run
> 
> $ python test.py
> UnicodeDecodeError: 'utf8' codec can't decode bytes in position 0-1:
> invalid data
> 
> by in python interactive, it is right
> 
>>>> s = u'张三'
> 
> why?

Does the "coding comment" match the actual encoding of the source file?

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list