# You've got a str "s".
s = s.decode('latin-1') # (or what the encoding might be …)
# Now "s" is a unicode object.
s = s.encode('utf-8') # Encode as UTF-8 string.
# Now "s" is a str again.
s = urllib2.quote(s) # URL encode.
# Now "s" is encoded the way you need it.
然后显式使用UTF-8:
并始终在文件中声明编码。见PEP 0263。
非UTF-8字符串需要先解码,然后编码:
相关问题 更多 >
编程相关推荐