未提供项目说明
read-source的Python项目详细描述
使用正确的编码读取Python3源文件
根据https://www.python.org/dev/peps/pep-0263/,
python3源文件编码默认为utf-8
。在
但是open()
的编码在windows上是gbk
,
所以不要使用没有编码的open
来读取python3源文件。在
示例:
fromread_sourceimportget_encoding,readprint(get_encoding('tests/source/gb18030/dash-star-dash.py'))# gb18030withread('tests/source/gb18030/dash-star-dash.py')asf:print(f.read())# -*- coding: gb18030 -*-
- 项目
标签: