i have txt files in '\data' such '1.txt'and '2.txt'. want add last line of these 2 files in file named '3.txt' i'm able add last line of '1.txt' '3.txt'
from sys import argv os.path import exists script,from_file,to_file=argv in_file=open(from_file) in_data=in_file.readlines() count=len(in_data) #print in_data[3] print count line=in_data[count-1] in_file.close() out_file=open(to_file,'w') out_file.write(line) out_file.close() in_file.close()
you opening output file 'w', means 'write', override existing content (as opposed 'a' - append).
so, assuming run script multiple times on each file in \data folder, overriding file on , on again, that's why single line @ end.
Comments
Post a Comment