1

I have a file, which is an assembly source with comments. These comments contain 1Ah character. It is a control character, the "substitute", but it also prints a nice right arrow in DOS, so someone long time ago thought it would be a shame not to use it.

Somehow, it works like end of file character for Python. All I do is:

f = open('file.asm')
for line in f:
    print line
f.close()

And everything goes ok just until the first entrance of 1Ah.

The question is, how to read this symbol along with other text?

akalenuk
  • 3,815
  • 4
  • 34
  • 56

2 Answers2

2

Open the file using universal line ending support:

f = open('file.asm', 'rU')

This avoids opening the file in native-platform text mode (in the C call) and prevents Windows from interpreting the \x1a code point as a line break.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
1

Try:

f = open('file.asm', 'rb')

It should open file in binary mode.

ElmoVanKielmo
  • 10,907
  • 2
  • 32
  • 46