fileinput.input('test.txt') => ERROR: input() already active

Peter Otten __peter__ at web.de
Mon Nov 20 03:58:50 EST 2006


cyberco wrote:

> Using fileinput.input('test.txt') I probably forgot to process all
> lines or so, since I get the error 'input() already active' when i try
> to call fileinput.input('test.txt') again. But how can I 'close' the
> previous version I opened? I have no handle to it or so...

fileinput.close()

Or you forego the global FileInput instance with

fi = fileinput.FileInput(...)
for line in fi:
   # process line
fi.close()

Personally, I use ordinary files instead.

Peter



More information about the Python-list mailing list