Solved

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

Posted on 2014-03-10
8
708 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

This article will show, step by step, how to integrate R code into a R Sweave document
The purpose of this article is to demonstrate how we can use conditional statements using Python.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

759 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

19 Experts available now in Live!

Get 1:1 Help Now