Long Live Python!

Steve Holden sholden at holdenweb.com
Thu Jul 12 13:38:12 EDT 2001


"Rufus V. Smith" <nospam at nospam> wrote in message
news:3b4dd783$0$2149 at wodc7nh6.news.uu.net...
>
> "Alex Martelli" <aleaxit at yahoo.com> wrote in message
> news:9ijpfk02a67 at enews4.newsguy.com...
> > My proposed solution relied on the fileinput module's "in-place"
> > behavior (WITH a backup, but that's optional I guess:-).  That
> > module nicely wraps whatever concerns may need to be wrapped, AND
> > works on as many files as you desire.
> >
> > def allbutfirst(files):
> >     for line in fileinput.input(files,inplace=1,backup='.bak'):
> >         if fileinput.filelineno()>1: print line,
> >
>
> I'm a definite Newbie, but to me this looks like it outputs the result
> to stdout, rather than creating a new file with the first line removed,
> which is what I thought the goal was.

The manual says: """Optional in-place filtering: if the keyword argument
inplace=1 is passed to input() or to the FileInput constructor, the file is
moved to a backup file and standard output is directed to the input file.
This makes it possible to write a filter that rewrites its input file in
place. If the keyword argument backup='.<some extension>' is also given, it
specifies the extension for the backup file, and the backup file remains
around; by default, the extension is '.bak' and it is deleted when the
output file is closed. In-place filtering is disabled when standard input is
read."""

So I guess the martellibot is correct again, which I know will stagger few
regular readers :^) .

don't-argue-with-a-bot-ly y'rs  - steve

--
http://www.holdenweb.com/








More information about the Python-list mailing list