美文网首页
python脚本中的问题

python脚本中的问题

作者: 心无旁骛_ | 来源:发表于2018-05-31 11:13 被阅读9次

简而言之:出现问题多敲一下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

相关文章

网友评论

      本文标题:python脚本中的问题

      本文链接:https://www.haomeiwen.com/subject/dmxqsftx.html