1. 程式人生 > >python3中報錯AttributeError: module 'sys' has no attribute 'setdefaultencoding'

python3中報錯AttributeError: module 'sys' has no attribute 'setdefaultencoding'

nic set encoding txt 分享 com src tde .com

技術分享圖片

  reload(sys)
    sys.setdefaultencoding("utf-8")
    f = open(.\\24.novel.txt,rb)
    str = f.read().decode(utf-8)
    f.close()

經過百度發現

Python3字符串默認編碼unicode, 所以sys.setdefaultencoding也不存在了。。。。。。

所以刪掉就好了。

python3中報錯AttributeError: module 'sys' has no attribute 'setdefaultencoding'