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

Fredrik Lundh fredrik at
Mon Nov 20 11:12:24 CET 2006

cyberco wrote:

> Another related question I have: The following piece edits in place,
> but ads whitelines between all lines of a Windows text file. Why?
> ===========================
> fi = fileinput.input('test.txt', inplace=1)
> for l in fi:
>     print l.replace('a', 'b')
> ===========================

     /.../ lines are returned including the trailing newline when it
     is present.

and "print" adds its own newline, of course.  try

     print text,




More information about the Python-list mailing list