How to handle multibyte string in Python

There are multibyte string functions in PHP to handle multibyte string (e.g:CJK script). For example, I want to count how many letters in a multi bytes string by using len function in python, but it return an inaccurate result (i.e number of bytes in this string)

japanese = "桜の花びらたち"
print japanese
print len(japanese)#return 21 instead of 7

Is there any package or function like mb_strlen in PHP?


Use Unicode strings:

# Encoding: UTF-8

japanese = u"桜の花びらたち"
print japanese
print len(japanese)

Note the u in front of the string.

To convert a bytestring into Unicode, use decode: "桜の花びらたち".decode('utf-8')

Need Your Help

Strange email format attachement encodnig

php email encoding attachment

Here is sample of email attachemt, it opens OK in Outlook express, but i really don't know how to decode this to useful data (it's .csv file) with php?

How can I emulate the browser zoom

jquery html5 css3 zoom

I'm searching a way to emulate the browser zoom. I found different approaches but nothing works well for me. For example, the "zoom" property doesn't seem to work on firefox. The -moz-transform doe...