Python and encoding, again -


i have next code snippet in python (2.7.8) on windows:

text1 = 'áéíóú' text2 = text1.encode("utf-8") 

and have next error exception:

unicodedecodeerror: 'ascii' codec can't decode byte 0xa0 in position 0: ordinal not in range(128) 

any ideas?

you forgot specify dealing unicode string:

text1 = u'áéíóú'  #prefix string "u" text2 = text1.encode("utf-8") 

in python 3 behavior has changed, , string unicode, don't need specify it.


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

Maven Javadoc 'Cannot find default setter' and fails -

actionscript 3 - Flash/AS3 - Saving a File without Prompt -