delete first line in a file

Petr Jakeš petr.jakes at tpc.cz
Fri Jun 30 09:25:03 EDT 2006


JH> this helps me!

JH> thank you very much!!!!!

JH> greetings, juergen
I am happy to see my postings (which I sent by accident to you only, not to
the list, see below) helped. But....:
Its a pity we can not see your solution (your code) here :(
It helps to others as well to see, how to solve some "problems"

Petr Jakes
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!
PJ> 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?! :-)
PJ> We are trying to understand that, but it is expected some effort on
PJ> your side as well :)
PJ> You didn't read the documentation properly!
PJ> try to experiment with the code by yourself as well!

PJ> Try:

PJ> 1) open your file
PJ> 2) use readlines() method
PJ> which returns the list of ALL rows from the file and store them to some
PJ> variable.
PJ> it can be done for example like:

PJ> all_lines = f.readlines()

PJ> (if you do not know, what the list is, start here:
PJ> http://docs.python.org/tut/node5.html#SECTION005140000000000000000)

PJ> 4) save the list members without its first member to the file
PJ> for example:

PJ> for line in all_lines[1:]:
PJ>     f.write(line)

PJ> 5) close the file

JH> Good luck
JH> Petr Jakes











JH>> thanks for your help!







More information about the Python-list mailing list