[英]how to read xml files in python if the encoding is different than UTF-8
[英]how to read bson files with utf-8 encoding?
我想读取一个带有utf-8
编码的bson
文件,但我不知道在哪里插入编码格式。
这是我的代码:
with open('filename.bson','rb') as f:
data = bson.decode_all(f.read())
您可以在open
函数中插入编码
with open('filename.bson','rb', encoding='utf-8') as f:
data = bson.decode_all(f.read())
import io
f = io.open('filename.bson', mode='rb', encoding='utf-8')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.