简体   繁体   中英

user input variables in python

I am fairly new to python, so this may seem rather basic, but i cannot find an answer. As i am experimenting with python i am making a simple program where the variable name is from input. eg; name = input()

when i run the program i input gabby so name = gabby, but if i close it and open it again i have to re input my name again.

How can i make it so that once i put gabby when it asks for input, name = gabby even when i close and rerun the program? (if that makes sense)

Thankyou

You'd want to write the data to a file or database. Getting a whole database set up can be a hassle so a file is probably the way to go for a small project. If all you want to store is the user name you could have something as simple as a text file that gets rewritten when the user changes their name. If you want to store more things like address or favorite color you might want to use something like JSON or YAML to serialize a larger data structure.

Here's a page on working with files in Python that should get you started.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM