[Tutor] Lists in a file
Robert Berman
bermanrl at cfl.rr.com
Sun Apr 26 20:18:07 CEST 2009
David,
You are processing a text file. It is your job to treat it as a file
comprised of lists. I think what you are saying is that each line in the
text file is a list. In that case
for line in fileobject:
listline = list(line)
Now, listline is a list of the text items in line.
Hope this helps.
Robert Berman
David Holland wrote:
> Hi,
>
> I am trying to create a program where I open a file full of lists and
> process them.
> However when the program does not recognize the lists as lists.
> Here is the relevant code :-
> def open_filedef():
> text_file =open ("voteinp.txt","r")
> lines = text_file.readlines()
>
>
> for line in lines:
> print line
> print line[0]
>
> text_file.close()
>
> And an example of the type of text :-
>
> ['a','b','c']
> ['e','d','f']
>
> Any ideas?
>
>
> Thanks in advance
>
>
> David Holland
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
More information about the Tutor
mailing list