Although i agreed with iCodez and you shouldn't use txt files (maybe SQL or even json)... i'll give you an alternative.
file1 = open("example.txt", "r")
alldatainfile1 = file1.read()
file1.close()
file2 = open("example.txt", "r")
alldatainfile2 = file2.read()
file2.close()
Now that you are working with vars and not files you could...
file1 = open("example.txt", "w")
file1.write(alldatainfile2)
file1.close()
Notice that i use "w" to write in the file (wich will delete all info and then save new one), but if you just want to add info to the file instead of deleting all you should use "a" for appending data.
Finally i suggest 3 tips:
- Backup your files before trying, the chances to delete important info is HIGH.
- Use a
For line in yourfile
code to check if the info is already there, and don't duplicate it if that's the case, but that should be done properly with json. - if that was json would be easy, since is not i'd try to give you a code to calculate the total of a row.
You could do this code:
total = 0
for line in alldatainfile1:
linesplit.split(" ") #3 whitespaces, since you got it that way
total = total + line[1]
print("total of column1: " + str(total))