[Tutor] help on dic creation
Alan Gauld
alan.gauld at btinternet.com
Tue Nov 6 06:30:06 CET 2012
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/
More information about the Tutor
mailing list