Most pythonic way to import a raw string from a txt file into a list? contents of "file.txt" looks like this (all in a single line):
["string1","anotha one","more text","foo","2the","bar","fin"]
I could easily copy/paste the string into my script but am sure there is a more dynamic method.
In basic pseudocode:
my_list = *contents of file.txt*
Read it as json
import json
with open('file.txt', 'r') as list_file:
my_list = json.load(list_file)
print (my_list)
['string1', 'anotha one', 'more text', 'foo', '2the', 'bar', 'fin']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With