tags:

views:

158

answers:

2
thestring = urllib.quote(thestring.encode('utf-8'))

This will encode it. How to decode it?

+4  A: 

What about

backtonormal = urllib.unquote(thestring)
Greg
+2  A: 

if you mean to decode a string from utf-8, you can first transform the string to unicode and then to any other encoding you would like (or leave it in unicode), like this

unicodethestring = unicode(thestring, 'utf-8')
latin1thestring = unicodethestring.encode('latin-1','ignore')

'ignore' meaning that if you encounter a character that is not in the latin-1 character set you ignore this character.

Vincent Osinga