How can I convert .txt file into a list python? -
within .txt file:
[['courtney fan', 'https://www.aaa.com', 'he guy'], ['courtney fan', 'https://www.bbb.com', 'dave butner', 'https://www.ccc.com', 'austin']] i tried method, doesn't split properly:
with open("/users/jj/desktop/courtney_fan.txt","r") f: sd = f.read().split() how can write nested list in python?
if data valid python literal (list, dict etc..) can use literal_eval function pythons built-in ast package. better solution using eval evaluate valid data structure, , not allow arbitrary code execution. there 0 cases using plain eval idea.
from ast import literal_eval open("/users/jj/desktop/courtney_fan.txt","r") f: my_list = literal_eval(f.read())
Comments
Post a Comment