On 31/10/12 01:01, Brayden Zhao wrote:

Here is my code and I dont know why my code is only reading the 500th
line of the file. Thanks for your help!

def fieldict(filename):
   D={}
   with open(filename) as FileObject:
     for lines in FileObject:
       linelist=lines.split('\t')
       Key=linelist[0]
       ValCity=(linelist[12]).strip()
       ValState=linelist[13]
       ValOne=linelist[2]
       ValTwo=linelist[6]
       ValThree=boolean(linelist[7])

You are assigning each line to the same variable.
So at the end of the loop ypou have the values of the last line.
You need to build a collection.

HTH
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

_______________________________________________
Tutor maillist  -  [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to