hello,

i'm a newbie programmer (and to python, double trouble :) and running into issues reading and writing files. i'm successfully running the code below to manipulate and remove the first few lines of a text file. The text file (file1.txt) is approx. 329kb but when i run the code it only writes a new 5kb file (file2.txt)... so the other 300 something kb below that is missing. how can i get the full file (to file2.txt) with only the first 4 lines removed???

so confused... please help!! :)

lines = file('./simple-retrieval/file1.txt', 'r').readlines()
del lines[0:4]
file('./simpleunwrapped/file2.txt', 'w').writelines(lines)

Thanks in advance!!!

I get the same exact results :(

here's another thing i should throw in... if i comment out the "del lines" line the results are the same... the whole file is still not copying to the new location.

it looks like the whole file never really opens...

As far as opening the file... am i doing it correctly?? i had an impression that readlines() as opposed to readline() is suppose to read the whole file into memory... is this true?

This works just fine for me using a Windows Vista machine:

lines = file('./simple-retrieval/file1.txt', 'r').readlines()

# show the first 10 lines for a test
print lines[:10]

del lines[0:4]

# now show the first 10 lines for a test
print lines[:10]

file('./simpleunwrapped/file2.txt', 'w').writelines(lines)
This question has already been answered. Start a new discussion instead.