Delete first line from file
pieter.claerhout at gmail.com
Tue Mar 1 13:50:51 CET 2005
what about the following?
f = open( 'file.txt', 'r' )
lines = f.readlines()
f = open( 'file.txt'.'w' )
f.write( '\n'.join( lines[1:] ) )
On Tue, 1 Mar 2005 12:42:00 +0000, Peter Nuttall
<p.s.nuttall at durham.ac.uk> wrote:
> On Tue, Mar 01, 2005 at 01:27:27PM +0100, Tor Erik S?nvisen wrote:
> > Hi
> > How can I read the first line of a file and then delete this line, so that
> > line 2 is line 1 on next read?
> > regards
> I think you can do something like:
> f=file.open("") #stuff here
> for line in f.readlines():
> if n: g.append(line)
> #write g to file
> if you are on a unix box, then using the standard untils might be a
> better idea.
pieter claerhout . pieter at yellowduck.be . http://www.yellowduck.be/
More information about the Python-list