I want to create a form, where you can fill in an input and it will saves the data in a .csv file. But if I close the script and open it again, to add more entrys, then it delets the old entrys in my .csv file. How can I add new informations, that it doesn't deletes the old ones. If that isn't possible, how can I create a random file name like: mydata_random.csv ?
The script:
import sys
try:
d = open("mydata.csv" , "w")
except:
print("Couldn't open the file")
sys.exit(0)
li = [1, "John Doe", "xxx"]
d.write(str(li[0]) + ";" + li[1] + ";"
+ str(li[2]).replace(".",",") + "\n")
dli = [[2, "John Doe" , "yyy"], [3, "John Doe", "zzz"]]
for element in dli:
d.write(str(element[0]) + ";"
+ element[1] + ";"
+ str(element[2]).replace(".",",") + "\n")
d.close()