Say there is some code I wrote, and someone else uses, and inputs their name, and does other stuff the code has.
name = input('What is your name? ')
money = 5
#There is more stuff, but this is just an example.
How would I be able to save that information, say, to a text file to be recalled at a later time to continue in that session. Like a save point in a video game.
You can write the information to a text file. For example:
(empty)
name = input('What is your name? ')
...
with open('mytext.txt', 'w') as mytextfile:
mytextfile.write(name)
# Now mytext.txt will contain the name.
Then to access it again:
with open('mytext.txt') as mytextfile:
the_original_name = mytextfile.read()
print the_original_name
# Whatever name was inputted will be printed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With