简而言之:出现问题多敲一下help()
一、python2中写的desc = desc.decode('utf-8')
在python3中报错:
AttributeError: 'str' object has no attribute 'decode'
解决:decode换成encode
desc = desc.encode('utf-8')
解释:str 类型只有 encode 方法, bytes 类型只有 decode 方法
二、
NameError: name 'file' is not defined
解决:file()改为open()
三、
python2中
if not rmap.has_key(cls):
解决:
if not cls in rmap:
解释:python3删除了has_key()方法。改为这种方式,也兼容python2
网友评论