Switching to Python 3 causing UnicodeDecodeError

前端 未结 3 1090
臣服心动
臣服心动 2020-11-27 05:04

I\'ve just added Python3 interpreter to Sublime, and the following code stopped working:

for directory in directoryList:
    fileList = os.listdir(directory)         


        
3条回答
  •  情歌与酒
    2020-11-27 05:21

    "as far as I know Python3 is supposed to support utf-8 everywhere ..." Not true. I have python 3.6 and my default encoding is NOT utf-8. To change it to utf-8 in my code I use:

    import locale
    def getpreferredencoding(do_setlocale = True):
       return "utf-8"
    locale.getpreferredencoding = getpreferredencoding
    

    as explained in Changing the “locale preferred encoding” in Python 3 in Windows

提交回复
热议问题