Solved

How to create a python program to capture data to a file?

Posted on 2014-03-10
8
711 Views
Last Modified: 2014-03-20
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?
0
Comment
Question by:asrawahi
  • 3
  • 3
  • 2
8 Comments
 
LVL 34

Expert Comment

by:Dan Craciun
ID: 39918349
We are prohibited on EE to do someone's homework, but can give pointers.

For ex, one way to write in a file in Python is:

f = open('myfile','w')
f.write('hello world\n') # \n is a line break
f.close()

Open in new window


HTH,
Dan
0
 
LVL 9

Expert Comment

by:techtonik
ID: 39924181
> 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.
0
 
LVL 28

Expert Comment

by:pepr
ID: 39929077
@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.
0
 
LVL 9

Expert Comment

by:techtonik
ID: 39929090
@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.
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 28

Accepted Solution

by:
pepr earned 500 total points
ID: 39929424
@techtonik: This is a student task with data that are strings. The student tasks should be solved as simply as possible. This is the task for reading the input, open the file, writing the data, and closing the file. The goal also is to learn what happenes when doing so. About pickle -- this is much more complicated to understand (for beginners).
0
 
LVL 9

Expert Comment

by:techtonik
ID: 39929452
0
 
LVL 34

Expert Comment

by:Dan Craciun
ID: 39939287
So the solution was that pickle is hard. Could not have guessed from the OP :)
0
 
LVL 28

Expert Comment

by:pepr
ID: 39944121
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 :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
What is Python programming? 3 103
Not needed 13 95
Example unit tests with AngularJS 3 40
Sums of coloumns in html/java 15 68
A set of related code is known to be a Module, it helps us to organize our code logically which is much easier for us to understand and use it. Module is an object with arbitrarily named attributes which can be used in binding and referencing. …
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now