Reputation: 375
How would i store the variable x on a specific line (the first)in a text file and recover it as the program opens.
Also how would i store data in a text file on a specific line
Upvotes: 0
Views: 3120
Reputation: 785
You should take a look at the open()
built-in.
#To write to a file:
with open("file.txt", "w") as f:
f.write("Data!")
#To read from a file:
with open("file.txt", "r") as f:
print(f.read())
Next time, you should check for duplicates:
easy save/load of data in python, Writing a Top Score to a data file.
Upvotes: 1