How can I determine the byte length of a utf-8 encoded string in Python?

Def utf8len(s): return len(s. Encode('utf-8')) Works fine in Python 2 and 3.

Thanks. I also found a website that shows you how to do it in several languages here: rosettacode. Org/wiki/String_length#Byte_Length_49 – user319862 Jul 16 at 2:27.

Assuming Python 2. X, use the string 'encode' method to convert from a character-string to a byte-string, then use len() like normal: str = u"¡Hola, mundo! " len(str) 13 # characters len(str.

Encode('utf-8')) 14 # bytes.

Much appreciated – user319862 Jul 16 at 2:28.

Assuming Python 2. X, use the string 'encode' method to convert from a character-string to a byte-string, then use len() like normal.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions