[Tutor] A Really Quick Question

Steve Haley sfhaley at earthlink.net
Sat Oct 22 16:18:16 CEST 2005



I am running Python 2.1 which ships with ArcView 9.1.  I am going through
the 2.1 tutorial and came across readlines().  Simply put it doesn't seem to
be behaving as the tutorial describes.  Specifically, I created a small text
file as shown below:


f=open("c:/python21/sfh_modules/test.txt", "w")

f.write("This is the second line\n")

f.write("This is the second line\n")

f.close()  # then closed and reopened in read mode

f=open("c:/python21/sfh_modules/test.txt", "r")

f.readlines(2)  # Here's my problem

['This is the first line\n', 'This is the second line\n']  # please note
this output


The tutorial seems to be telling me that 'f.readlines(2) should read out 2
bytes plus what is needed to complete the current line.  Instead, it is
reading out the entire file no matter what I enter as a parameter.  I know I
am going to feel really dumb when I hear the explanation but please remember
I'm new to this.


Thanks very much,


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20051022/ef337357/attachment.htm

More information about the Tutor mailing list