asrawahi
asked on
How to create a python program to capture data to a file?
I was given an assignment to capture the following in the input screen:
Student Name
Student ID
Gender
Student Address
Is there any way to save these user inputs into a file and query them or update them by using python?
Student Name
Student ID
Gender
Student Address
Is there any way to save these user inputs into a file and query them or update them by using python?
> Is there any way to save these user inputs into a file and query them or update them
> by using python?
Yes. Python allows to save data structures to file and restore them. The process is called serialization. See pickle module for details.
> by using python?
Yes. Python allows to save data structures to file and restore them. The process is called serialization. See pickle module for details.
@techtonik: Actually, saving a data and saving the data structures are two slightly different things. The serialization is for the second purpose. More often, it is used for passing the parts of the data structures throught network or for storing the state of the program say during hibernation.
@pepr: I don't see how it contradicts with the question. Operating with data in structured manner is more convenient than manually converting everything to strings. There is no requirement to save user input into human readable format, so for this question saving data and saving structured data is the same.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
@pepr: http://learnpythonthehardway.org/ =)
So the solution was that pickle is hard. Could not have guessed from the OP :)
Well, the question tag even says "Python list", which makes sense in the context.
@Dan: pickle is possibly a bit sour to be swallowed by beginners to get that "Aha!" kind of understanding :)
@Dan: pickle is possibly a bit sour to be swallowed by beginners to get that "Aha!" kind of understanding :)
For ex, one way to write in a file in Python is:
Open in new window
HTH,
Dan