debugging fileinput

John J. Lee jjl at pobox.com
Tue Apr 22 14:42:50 EDT 2003


"Kyoskyu" <me at privacy.net> writes:

[...]
> import fileinput, string
> for line in fileinput.input():
> 	process(strip(line))
> 
> However, for some reason, this snippet of code gets to the end of the file
> and starts again at the beginning.  I'm at a loss as to how to debug this
> problem.  If someone has any ideas or knows the reason, I'd appreciate the
> help.  Thanks.

Don't know the reason offhand, but here are some debugging ideas:

1. State the file to iterate over explicitly (as an argument to
   fileinput.input, IIRC: for line in fileinput.input(myfilename))

2. Does process() do any sys.stdout.seek()s?  Or call functions that
   might do that?


John




More information about the Python-list mailing list