Read a text file with non-ASCII characters in an unknown encoding

后端 未结 2 1185
一生所求
一生所求 2020-12-16 14:59

I want to read a file that contains also German and not only characters. I found that i can do like this

  >>> import codecs
  >         


        
2条回答
  •  我在风中等你
    2020-12-16 15:30

    I believe the file is being read correctly but is using the wrong encoding when output. This is based on the fact that you get the proper results in IDLE.

    I would suggest trying to use print(line.encode('utf-8')) but I'm afraid I don't know if Python 3 will print a bytes object properly.

提交回复
热议问题