Here is an example how to do this. I had to create your kind of data file first to use it properly ...
data_str = """\
1846440556
1846440521
1846440491
1846440505
1846441137
1846441102
1846441080
1846441331
1846441323
1846441315"""
# let's create your data file from the string
fout = open("MyData1.txt", "w")
fout.write(data_str)
fout.close()
# read the data file in as a list
fin = open( 'MyData1.txt', "r" )
data_list = fin.readlines()
fin.close()
# test it ...
print data_list
print '-'*60
# remove list items from index 3 to 5 (inclusive)
del data_list[3:5+1]
# test it ...
print data_list
# write the changed data (list) to a file
fout = open("MyData2.txt", "w")
fout.writelines(data_list)
fout.close()
vegaseat
DaniWeb's Hypocrite
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417
What is your error message?
bumsfeld
Nearly a Posting Virtuoso
1,445 posts since Jul 2005
Reputation Points: 404
Solved Threads: 184
Looks like you really butchered vegseat's code. Let me rewrite it a little:
""" assume part of your list1.txt data file looks like this:
1846440556
1846440521
1846440491
1846440505
1846441137
1846441102
1846441080
1846441331
1846441323
1846441315
"""
# read the data file in as a list
fin = open( 'list1.txt', "r" )
data_list = fin.readlines()
fin.close()
# test first 5 list items ...
print data_list[:5]
print '-'*60
# remove list items from index 3 to 5 (inclusive)
del data_list[3:5+1]
# test first 5 list items ...
print data_list[:5]
# write the changed data (list) to a file
fout = open("list2.txt", "w")
fout.writelines(data_list)
fout.close()
bumsfeld
Nearly a Posting Virtuoso
1,445 posts since Jul 2005
Reputation Points: 404
Solved Threads: 184
When i try to use this code i still have the data in the orginial filem how do i remove them from the first file?
Replacefout = open("list2.txt", "w")
with
fout = open("list1.txt", "w")
to overwrite the original file.
vegaseat
DaniWeb's Hypocrite
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417