'str' object has no attribute 'decode' in Python3

后端 未结 3 757
北恋
北恋 2020-12-01 18:59

I\'ve some problem with \"decode\" method in python 3.3.4. This is my code:

for lines in open(\'file\',\'r\'):
    decodedLine = lines.decode(\'ISO-8859-1\')         


        
3条回答
  •  悲&欢浪女
    2020-12-01 19:49

    open already decodes to Unicode in Python 3 if you open in text mode. If you want to open it as bytes, so that you can then decode, you need to open with mode 'rb'.

提交回复
热议问题