delete first line in a file

Juergen Huber juergen.huber at kirchnersoft.com
Fri Jun 30 09:07:48 EDT 2006


this helps me!

thank you very much!!!!!

greetings, juergen



JH> Fredrik Lundh wrote:

>> Juergen Huber wrote:

>>

>>> ok...i thought as much, that i have to copy this file!

>>>

>>> how will i do that?!

>>> how will i fix this file => delete the first line?!

>>>

>>> with which commands could i do that?!

>>

>> start here:

>>

>> http://docs.python.org/tut/node9.html#SECTION009200000000000000000

>>

>> </F>

JH> that documentation i have already read, but it wouldn`t help me for my

JH> problem!

JH> i know, how i can read the first line an print them on the screen!

JH> but...how can i say python, delete the first line?!

JH> thats my problem!

as Fredrik told you, you can not delete the first line directly!!!

JH> in the entry of my posting i wrote, that i am a newbie and so please

JH> understand me, that i ask so questions?! :-)

We are trying to understand that, but it is expected some effort on

your side as well :)

You didn't read the documentation properly!

try to experiment with the code by yourself as well!

Try:

1) open your file

2) use readlines() method

which returns the list of ALL rows from the file and store them to some
variable.

it can be done for example like:

all_lines = f.readlines()

(if you do not know, what the list is, start here:

http://docs.python.org/tut/node5.html#SECTION005140000000000000000)

4) save the list members without its first member to the file

for example:

for line in all_lines[1:]:

f.write(line)

5) close the file



Good luck

Petr Jakes











JH> thanks for your help!






More information about the Python-list mailing list