Question

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.

Était-ce utile?

La solution 2

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

Autres conseils

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top