Im trying to reach elements of two lists who both are within a list. And this last list (containing the other two lists) is in a file.
When I print the big list from my file, it looks like: ['[0,1],[2,3]'] and it is called rader.
rader = ['[0,1],[2,3]']
I'm trying to print the elements in the big list with the following command:
print(rader[0][0])
which should give me the number 0 right? But when I do this I get an error: 'IndexError: list index out of range'.
I think that the problem is that when I open my txt.file with the list in it and read from it (file = open('eddie.txt','r'))
, it interprets the whole thing as a String! Is that why I cant reach the elements in the list?
I want it like [[0,1],[2,3]] and not ['[0,1],[2,3]'] from the txt.file(I think?) How do I do this?
Here is my code:
from Tv_LABB2 import *
fil = open('edvin.txt','r', encoding = 'UTF-8')
rader = []
rad = fil.readline()
while rad !='':
rader.append(rad)
rad = fil.readline()
fil.close()
fil = open('edvin.txt')
print(rader) (this is == ['[0,1],[2,3]'])
fil.close()
tv1 = TV('VardagsrumsTV',str(rader[0]),str(rader[1]))
tv2 = TV('KöksTv',str(rader[2]),str(rader[3]))
As you can see Im importing some functions from another file, this code doesn´t run without it, but I think you understand my question!