string length problem?

Peter Otten __peter__ at web.de
Wed Jan 7 06:26:12 EST 2009


Qian Xu wrote:

> why the code
>   print len(u"»test«")
> returns 8 instead of 6?

You may have declared an encoding that differs from the one your editor
actually uses, e. g.

# -*- coding: iso-8859-1 -*-
print len(u"»test«")

whereas your editor writes UTF-8.

Peter




More information about the Python-list mailing list