Solved

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

Posted on 2014-03-10
8
738 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 35

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 29

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
Tutorials alone can't teach real engineering

So we built better training tools.

-Hands-on Labs
-Instructor Mentoring
-Scenario-Based Tests
-Dedicated Cloud Servers

All at your fingertips. What are you waiting for?

 
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
 
LVL 29

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 35

Expert Comment

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

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

A new era in Cloud training has arrived.

A day that will go down in Cloud history.. But are you ready for it? Will you accept this Cloud challenge?

Question has a verified solution.

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

Article by: Swadhin
Introduction of Lists in Python: There are six built-in types of sequences. Lists and tuples are the most common one. In this article we will see how to use Lists in python and how we can utilize it while doing our own program. In general we can al…
If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

628 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