Long Live Python!

Rufus V. Smith nospam at nospam
Fri Jul 13 12:53:39 EDT 2001


"Steve Holden" <sholden at holdenweb.com> wrote in message
news:kel37.3407$u76.70914 at e420r-atl3.usenetserver.com...
> "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.

Silly Newbie!

>
> 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."""

That is SO COOL!

(Copying this to my Python tips folder and looking up that FileInput
module..)










More information about the Python-list mailing list