Solved

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

Posted on 2014-03-10
8
721 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 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
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 
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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Math Equation 23 122
Getting the NAO robot to play soccer 1 39
Python 3.5.2 - Script Help 3 89
Batch File- Finding Drive Description 11 39
Flask is a microframework for Python based on Werkzeug and Jinja 2. This requires you to have a good understanding of Python 2.7. Lets install Flask! To install Flask you can use a python repository for libraries tool called pip. Download this f…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

679 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