python - python3 file to array with quotes -
this question has answer here:
i have data in file following:
[['1','1','abc'],['2','2','pqr'],['3','3','xyz']] i trying load data in list variable.
with open('abc.txt') d: text = d.readlines() i got following output:
>>> text ["[['1','1','abc'],['2','2','pqr'],['3','3','xyz']]"] then tried command text = d.read() got following result:
"[['1','1','abc'],['2','2','pqr'],['3','3','xyz']]" i trying achieve output as:
>>> text [['1','1','abc'],['2','2','pqr'],['3','3','xyz']] kindly, guide me fulfill want to.
you can achieve desired output bywriting code:
import ast open('abc.txt') f: ls = ast.literal_eval(f.read()) welcome in advance. 😊
Comments
Post a Comment