Setting the correct encoding when piping stdout in Python

后端 未结 10 2447
迷失自我
迷失自我 2020-11-22 01:21

When piping the output of a Python program, the Python interpreter gets confused about encoding and sets it to None. This means a program like this:

# -*- co         


        
10条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-22 02:14

    I had a similar issue last week. It was easy to fix in my IDE (PyCharm).

    Here was my fix:

    Starting from PyCharm menu bar: File -> Settings... -> Editor -> File Encodings, then set: "IDE Encoding", "Project Encoding" and "Default encoding for properties files" ALL to UTF-8 and she now works like a charm.

    Hope this helps!

提交回复
热议问题