There was some help already, but I was still confused.
I have a line in Unicode:
title = u'πtest' title_length = len(title)
But! I need len (title) to be 6. Customers expect this to be 6 because they seem to be counted differently than on the backend.
As a workaround, I wrote this little helper, but I'm sure it can be improved (with sufficient knowledge of coding) or, possibly, even incorrectly.
title_length = len(title) + repr(title).count('\\U') #6
1. Is there a better way to get a length of 6 ?:-)
I assume that (Python) counts the number of Unicode characters, which is 5. Are clients counting the number of bytes?
2. Will my logic be violated for other Unicode characters that require, for example, 4 bytes?
Running Python 2.7 ucs4.
python unicode
kev
source share