Conitnue to read through NUL

╄→尐↘猪︶ㄣ 提交于 2019-12-11 13:53:16

问题


I got a .dat file, encoded in ANSI which contains NUL caracters (not only !).

I wan't to read it into a str object iot cut something in the whole str obtained.

But file.read() stops when the first NUL is reached.

I'm lost :)

My code :

file=open(source, mode='rt')
fulltext=file.read()
print(fulltext)

NUL is show with Notepad++ I'm on Windows XP, with PortablePython 3.2 The file is a special DAT file that can be edited with notepad as a text.


回答1:


If you want to read bytes like 0, chances are your file is a binary file. Read in binary mode rb instead of text mode rt.




回答2:


As Evert has commented in my question, the problem was focused on the use of Pyscripter ! So, this question is closed :)



来源:https://stackoverflow.com/questions/13490794/conitnue-to-read-through-nul

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!