
May 25th, 2004, 10:42 PM
|
 |
Hello World :)
|
|
Join Date: Mar 2003
Location: Hull, UK
|
|
Another solusion, a mix of the too aproches really.
Code:
#!/usr/bin/env python
lines = file('file.txt', 'r').readlines()
del lines[slice:to:delete]
file('file.txt', 'w').writelines(lines)
Just replace the bold bit with the line number you want to delete - remembering that lists/arrays start with 0 and watch that anoying line go bye bye. But your example should work all you have to do is write the data out with writelines()
The draw back being that this aproch reads the whole file into memory but then Python programs do that every day so don't worry about it  .
Have fun,
Mark.
__________________
programming language development: www.netytan.com – Hula
Last edited by netytan : May 25th, 2004 at 10:47 PM.
|