Delete first line from file

Peter Nuttall p.s.nuttall at durham.ac.uk
Tue Mar 1 07:42:00 EST 2005


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:

n=false
f=file.open("") #stuff here
g=[]
for line in f.readlines():
	if n: g.append(line)
	n=true

#write g to file 

if you are on a unix box, then using the standard untils might be a
better idea. 

Pete




More information about the Python-list mailing list