Skip to main content
 首页 » 编程设计

python之获取 python 文件或环境的 CURRENT_FILE_ENCODING

2025年05月04日13lhb25

如果可能的话,如何从正在运行的 python 进程中判断源文件的编码?

请您参考如下方法:

encoding = open(__file__).encoding

这在某些情况下可能有效,但请注意 http://docs.python.org/library/stdtypes.html#file.encoding