Reading from text files

Thomas Philips tkpmep at
Sun Feb 22 21:13:12 CET 2004

In the course of playing around with file input and output, I came
across some behavior that is not quite intuitive. I created a simple
text file, test.txt, which contains only 3 lines, and which I expect
will have 5 characters (the digits 1, 2, and 3, and two newline
characters, the first after 1 and the second after 2). Here it is in
all its glory:

However, when I read it using open()and then view it using
>>>;; file.tell()
I get:

Python thinks there are 7 characters in the file! If I type 
>>>; OR >>>;
I get

gives me what I expected to get with;

It appears that Python sometimes counts each of the newline escape
sequences as 2 separate characters and at other times as 1 indivisible
character. What is the appropriate way to think about these

Thomas Philips

More information about the Python-list mailing list