string length problem?

Qian Xu quian.xu at stud.tu-ilmenau.de
Wed Jan 7 06:28:17 EST 2009


Qian Xu wrote:

> Hi All,
> 
> why the code
>   print len(u"»test«")
> returns 8 instead of 6?
> 
> Best regards
> Qian

I have solved the problem myself.

# -*- coding: utf-8 -*-
print len(u"»test«")

--- or ---
s = "»test«"
print len(s.decode("utf-8"))

--Qian



More information about the Python-list mailing list