问题
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