Hello, I was using Python 2.2.2 (#37, Oct 14 2002, 17:02:34) [MSC 32 bit (Intel)] on win32 to write a file to parse a text file. The file was divided in two parts, so I wrote something like this: file = open("foobar" ,"r") for line in file: #read a few lines break for line in file: read rest of lines A chunk of the middle part of the file ends up missing. Oddly, it's not the section just after the first few lines are read. I've attached an example script and data file which shows this problem on my system (Windows 2000). The workaround I'm using (which works) is : file = open("foobar","r") while 1: line = file.readline() if line is what I want: break for line in file: do stuff Which seems to work
Logged In: YES user_id=593130 I believe that the file and iteration specs leave reiteration behavior undefined, making this not-a-bug, even if annoying. In any case, this is known behavior. Explanation (from c.l.py postings): a 2.2 file iterator (apparently a separate object from file object itself) reads blocks of the file and then yields a line at a time. When you break, leftover read data in the last block is discarded. In 2.3, I believe file object is its own iterator. Don't know if it fixed this wart. In any case, perhaps you could close this.
Logged In: YES user_id=593130 Agreed. I recommend you check behavior of 2.3 (due by end of month - now in final bug fix stage) and raise issue on comp.lang.python if not satifactorily changed.