I need to read a list from a txt file and import as a list variable into my .py file. I could use the import function, but the program must be compiled and when it\'s compiled t
try to use ast.literal_eval
:
>>> a = str([['preset1','a1','b1'],['preset2','a2','b2'],['preset3','a3','b3'],['preset4','a4','b4']])
>>> a
"[['preset1', 'a1', 'b1'], ['preset2', 'a2', 'b2'], ['preset3', 'a3', 'b3'], ['preset4', 'a4', 'b4']]"
>>> import ast
>>> ast.literal_eval(a)
[['preset1', 'a1', 'b1'], ['preset2', 'a2', 'b2'], ['preset3', 'a3', 'b3'], ['preset4', 'a4', 'b4']]
>>>