N
Nick Jacobson
Is this a bug?
This code involves the file methods "seek" and "tell". Even though
the file pointer is in the middle of the file, "tell" returns a
position at the end of the file!
fp = file("test.txt")
#read in some of the file:
for line in fp:
if line == "blah3\n":
break
fpos = fp.tell() #save the current position...
for line in fp:
print line #prints "asdf", so it wasn't at the end of the file
fp.seek(fpos) #rewind?
for line in fp:
print line #prints nothing, because it's at the end of the file!
The test.txt file is:
blah1
blah2
blah3
asdf
This code involves the file methods "seek" and "tell". Even though
the file pointer is in the middle of the file, "tell" returns a
position at the end of the file!
fp = file("test.txt")
#read in some of the file:
for line in fp:
if line == "blah3\n":
break
fpos = fp.tell() #save the current position...
for line in fp:
print line #prints "asdf", so it wasn't at the end of the file
fp.seek(fpos) #rewind?
for line in fp:
print line #prints nothing, because it's at the end of the file!
The test.txt file is:
blah1
blah2
blah3
asdf