I have this bunch of code, which is supposed to write dataadress to a new line in a file.
file = open("addresslist.txt", "w")
file.write(str(dataaddress) + "\n")
file.close()
This code is in a loop and every time it loops, dataadress changes. The problem is that when the script finishes, the only instance of dataadress being saved to the file is the last one, because everytime it loops, instead of writing to a new line it just overwrites the first one.
I thought that adding the "\n" at the end of the string in file.write() would fix this issue, but it didn't. I also tried adding file=f like in this post but that just brought up the error message TypeError: write() takes no keyword arguments.
How should I fix this?