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

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -