Re: [Tutor] Reading from files problem

2009-04-21 Thread ALAN GAULD
> this worked for me fine. I'm glad you solved tyour problem. But you have done so in an extremely inefficient way, both inefficient in the way it uses computer resources - both CPU and storage, and inefficient in the way it uses your time - way more code than you need. If you only need an answ

Re: [Tutor] Reading from files problem

2009-04-20 Thread Chris Castillo
this worked for me fine. #Author - Chris Castillo #Created 4/19/09 #Program 6 import time #Open and read text file with student information gradesfile = open("grades.dat", "r") time_acc = time.asctime() #Ask user for student ID to lookup student information sought_id = raw_input("Please enter a

Re: [Tutor] Reading from files problem

2009-04-20 Thread Alan Gauld
"Scott SA" wrote May have been a bad assumption on my part as I envisioned pickling a dict. and that just got too complicated. A pickled dict? That would be a shelve mebbe? PS. My email is acting up, did my prev. message actually make it to the list? Yes, I saw it just after sending m

Re: [Tutor] Reading from files problem

2009-04-20 Thread Scott SA
On Apr 20, 2009, at 12:59 AM, Alan Gauld wrote: You might want to store the data in a dictionary keyed by ID number? I had thought of suggesting this, but it appeared that the OP was going to re-iterate the file each time he wished to query the CSV. May have been a bad assumption on my par

Re: [Tutor] Reading from files problem

2009-04-20 Thread spir
Le Mon, 20 Apr 2009 07:59:15 +0100, "Alan Gauld" s'exprima ainsi: > So I'd change the structure to be like this(pseudo code) > > students = dict() # empty dict > for line in gradesfile: > line = line.split(',') > s = Student() > s.id = line[0] > s.lastname = line[1] > etc...

Re: [Tutor] Reading from files problem

2009-04-20 Thread spir
Le Mon, 20 Apr 2009 07:59:15 +0100, "Alan Gauld" s'exprima ainsi: > > #Open and read text file > > > > gradesfile = open("grades.dat", "r" > > for lines in gradesfile: > >lines = lines.split(",") > >identifier = lines[0] > >lastname = lines[1] > >firstname = lines[2] > >major

Re: [Tutor] Reading from files problem

2009-04-20 Thread Alan Gauld
"Chris Castillo" wrote I am trying to open a text file and read multiple lines containing the following: 745777686,Alam,Gaus,CIS,15,30,25,15,5,31,15,48,70,97 888209279,Anderson,Judy,Math Ed,14,30,30,13,11,30,16,18,58,72 You could use the CSV module for this, although a basic for loop is fin

Re: [Tutor] Reading from files problem

2009-04-19 Thread Scottsa
Hi Chris, On Apr 19, 2009, at 5:45 PM, Chris Castillo wrote: I am trying to open a text file and read multiple lines containing the following: 745777686,Alam,Gaus,CIS,15,30,25,15,5,31,15,48,70,97 888209279,Anderson,Judy,Math Ed,14,30,30,13,11,30,16,18,58,72 This is CSV format data (comma sep

Re: [Tutor] Reading from files problem

2009-04-19 Thread Chris Castillo
so how would I check to see if the student number entered by the user matches one of the student numbers in the file and then display that students info? On 4/19/09, R. Alan Monroe wrote: > >> gradesfile = open("grades.dat", "r >> for lines in gradesfile: >> [snip] >> That's what I have so far bu

Re: [Tutor] Reading from files problem

2009-04-19 Thread R. Alan Monroe
> gradesfile = open("grades.dat", "r > for lines in gradesfile: > [snip] > That's what I have so far but I have a feeling I shouldn't use a for > loop. Actually a for loop seems like the right tool for this job, assuming you really _do_ want to process every line in the file. Alan _