How to change file system encoding via python?

后端 未结 2 1731
甜味超标
甜味超标 2020-12-19 03:36
>>> import sys
>>> sys.getfilesystemencoding()
\'UTF-8\'

How do I change that? I know how to change the default system encoding.<

2条回答
  •  甜味超标
    2020-12-19 04:11

    The file system encoding is, in many cases, an inherent property of the operating system. It cannot be changed — if, for some reason, you need to create files with names encoded differently than the filesystem encoding implies, don't use Unicode strings for filenames. (Or, if you're using Python 3, use a bytes object instead of a string.)

    See the documentation for details. In particular, note that, on Windows systems, the file system is natively Unicode, so no conversion is actually taking place, and, consequently, it's impossible to use an alternative filesystem encoding.

提交回复
热议问题