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

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -