- 获得当前设备默认编码格式(open, fileinput 的默认编码格式都是这个):
import locale
locale.getpreferredencoding()
- 修改open 和 fileinput 的默认使用编码:
# open
open(filename, encoding='utf-8')
# fileinput
fileinput.input(filename, openhook=fileinput.hook_encoded("utf-8"))
import locale
locale.getpreferredencoding()
# open
open(filename, encoding='utf-8')
# fileinput
fileinput.input(filename, openhook=fileinput.hook_encoded("utf-8"))
本文标题:python 容易忘记但实用的函数
本文链接:https://www.haomeiwen.com/subject/sxcwhktx.html
网友评论