代码语言:javascript
复制import cgi
s = '<>&'
s = u'哈哈'
print type(s)
print s
r = cgi.escape(s)
print type(r)
print r
r = r.encode('gbk')
print type(r)
print r
# <type 'unicode'>
# <>&哈哈
# <type 'unicode'>
# <>&哈哈
# <type 'str'>
# <>&哈哈