I want to save all values (cases1) in a text file. But, when I execute the following code only the last value i.e 7 is saved in the variables.txt
cases1 = [1, 2, 3, 4, 5, 6,7]
for j in cases1:
promfac=j
dict = {'promfac':promfac}
varsave=repr(dict)
file = open("variables.txt","w")
file.write(varsave + '\n')
file.close()
Following is the output:
{'promfac': 7}
I want my output to be like this:
{'promfac': 1}
{'promfac': 2}
{'promfac': 3}
{'promfac': 4}
{'promfac': 5}
{'promfac': 6}
{'promfac': 7}