This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author hdima
Recipients
Date 2002-11-29.09:13:16
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
Consider following piece of code:

f = file("test.txt", "rb")
pos = f.tell()
for line in f:
	print "%u: '%s'" % (pos, line)
	pos = f.tell()

During the code execution we have following result:

0 'Line 1'
63 'Line 2'
63 'Line 3'
...
63 'Line 9'

However, following piece of code works fine:

f = file("test.txt", "rb")
while True:
	pos = f.tell()
	line = f.readline()
	if line == "":
		break
	print "%u: '%s'" % (pos, line)

It prints:

0 'Line 1'
7 'Line 2'
14 'Line 3'
...
56 'Line 9'

It seems a file iterator makes file.tell() to tell
positions of some internal blocks used by the iterator.
History
Date User Action Args
2007-08-23 14:09:12adminlinkissue645594 messages
2007-08-23 14:09:12admincreate