Reading a list of lists into Python -


I've created a list of lists to store the student's score statistics. The list is called "class 1" and the name of each student is 3 score. I can fix this list and write a file that shows the data in the correct format:

  class1 = [["Tom", 7,2,1], [ "Joe", 8,0,0], ["Adlape", 90,0]]  

When I wrote that way with which I am happy:

<'>' '' ',' '', ',' '', ',' The problem occurs when I try to read the same list. Each sublist is read as a string. I can not change it.

Here is the code:

  class1 = [line.strip () in the open for the line ("data2.txt", 'r')]  

This is a list that looks like read, as you can see that there is appropopopes around each sub-list, which means they have the wire in the class 1 list:

< ['Tom', 7, 2, 1] ", [['' 8, 0, 0] '', ['adelpay', 9, 0, 0]"]

Can someone help me, I've searched a lot, but no one can get it from the same problem

Thanks Tom

  & gt; & Gt; & Gt; Import A & G; & Gt; & Gt; Open in line for classes ('/ path / to / data2.txt', 'r'): Classes = [ast.literal_eval (line.strip ()) in classes]> gt; & Gt; & Gt; Print lines [['Tom', 7, 2, 1], ['Joe', 8, 0, 0], ['Adelpay', 9, 0, 0]]  

Comments