'utf-8' codec can't decode byte reading a file in Python3.4 but not in Python2.7

后端 未结 2 1005
没有蜡笔的小新
没有蜡笔的小新 2021-01-04 19:53

I was trying to read a file in python2.7, and it was readen perfectly. The problem that I have is when I execute the same program in Python3.4 and then appear the error:

2条回答
  •  梦毁少年i
    2021-01-04 20:35

    Ok, I did the same as @unutbu tell me. The result was a lot of encodings one of these are cp1250, for that reason I change :

    f = open(filename,'r')
    

    to

    f = open(filename,'r', encoding='cp1250')
    

    like @triplee suggest me. And now I can read my files.

提交回复
热议问题