How to find number of characters in a unicode string?

Preben Randhol randhol+valid_for_reply_from_news at pvv.org
Mon Sep 18 22:18:14 CEST 2006


Hi

If I use len() on a string containing unicode letters I get the number
of bytes the string uses. This means that len() can report size 6 when
the unicode string only contains 3 characters (that one would write by
hand or see on the screen). Is there a way to calculate in characters
and not in bytes to represent the characters.

The reason for asking is that PyGTK needs number of characters to set
the width of Entry widgets to a certain length, and it expects viewable
characters and not number of bytes to represent them.


Thanks in advance


Preben



More information about the Python-list mailing list