UnicodeDecodeError: 'charmap' codec can't decode byte X in position Y: character maps to

前端 未结 9 1530
情歌与酒
情歌与酒 2020-11-22 00:43

I\'m trying to get a Python 3 program to do some manipulations with a text file filled with information. However, when trying to read the file I get the following error:

9条回答
  •  鱼传尺愫
    2020-11-22 00:56

    As an extension to @LennartRegebro's answer:

    If you can't tell what encoding your file uses and the solution above does not work (it's not utf8) and you found yourself merely guessing - there are online tools that you could use to identify what encoding that is. They aren't perfect but usually work just fine. After you figure out the encoding you should be able to use solution above.

    EDIT: (Copied from comment)

    A quite popular text editor Sublime Text has a command to display encoding if it has been set...

    1. Go to View -> Show Console (or Ctrl+`)

    1. Type into field at the bottom view.encoding() and hope for the best (I was unable to get anything but Undefined but maybe you will have better luck...)

提交回复
热议问题