utf - string translation

Duncan Booth duncan.booth at invalid.invalid
Wed Nov 22 20:02:48 CET 2006


hg <hg at nospam.com> wrote:

>> or in other words, put this at the top of your file (where "utf-8" is
>> whatever your editor/system is using):
>> 
>>    # -*- coding: utf-8 -*-
>> 
>> and use
>> 
>>    u'<text>'
>> 
>> for all non-ASCII literals.
>> 
>> </F>
>> 
> 
> Hi,
> 
> The problem is that:
> 
> # -*- coding: utf-8 -*-
> import string
> print len('a')
> print len('à')
> 
> returns 1 then 2

And if you do what was suggested and write:

# -*- coding: utf-8 -*-
import string
print len(u'a')
print len(u'à')

then you get:

1
1



More information about the Python-list mailing list