I have a file from which contains on every line the following: name of the file, length of the list, the actual list. Here is an example:
a.txt 3 [4,2,9]
b.txt 5 [1,6,5,2,8]
c.txt 7 [1,2,3,4,5,6,7]
and so on.
I have managed to read everything until the list, but the list gets read as strings. For example, for the first one, the output is '[4,','3,','4]'
and I want to have a normal list.
This is the code I have so far, but it's just a simple reading from the file:
f = open('example.txt', 'r')
for eachLine in f:
a = eachLine.strip().split()
l = a[2]
print l
f.close()
I used l=a[2]
but this doesn't store my entire list, it only stores the first element from it.
How can I store the list from the file into a list in python?