简体   繁体   中英

how to read bson files with utf-8 encoding?

I want to read a bson file with utf-8 encoding but I don't know where to insert the encoding format.

here is my code:

with open('filename.bson','rb') as f:
    data = bson.decode_all(f.read())

You can insert encoding within open function

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')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM