简体   繁体   中英

I am trying to read a utf-8 file in python and keep BOM, but BOM is automatically deleted when i do file.read

I have done the following:

a = open(text, encoding='utf-8').read

I am trying to count the words in this text file and include the BOM.

However, when I use readline , the BOM is not deleted.

Does anyone know how to keep the BOM with read not readlines ?

Hello I try this and work:

a = open('text.txt',encoding='utf-8').read()
print(a)

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