Python 3 chokes on CP-1252/ANSI reading

前端 未结 3 1358
野趣味
野趣味 2020-12-04 02:17

I\'m working on a series of parsers where I get a bunch of tracebacks from my unit tests like:

  File \"c:\\Python31\\lib\\encodings\\cp1252.py\", line 23, i         


        
3条回答
  •  情歌与酒
    2020-12-04 02:42

    You can relax the error handling.

    For instance:

    f = open(filename, encoding="...", errors="replace")
    

    Or:

    f = open(filename, encoding="...", errors="ignore")
    

    See the docs.

    EDIT:

    But are you certain that the problem is in reading the file? Could it be that the exception happens when something is written to the console? Check http://wiki.python.org/moin/PrintFails

提交回复
热议问题