Tuesday, January 6, 2009

Cut lines in file using Python

# cut top 10 list in files
# load entire file in memory

text = open(targetfilename).readlines()
count = 0

while count < 10 :
del text[0]
count = count + 1

# store 10 lines back new file

fout = open(outputfilename,'w')
fout1.writeines(text)
fout1.close()

0 comments: