I have a file that I'd like to import into an array but have each entry as an index so I can call each specific one.
File(testing_array.txt):
["zero", "one", "two", "three", "four", "five"]
Script:
f = open('testing_array.txt').read()
array = [f]
print (array[0])
print (array[1])
Output:
["zero", "one", "two", "three", "four", "five"]
Traceback (most recent call last):
File "testing_array.py", line 4, in <module>
print (array[1])
IndexError: list index out of range
I've tried a for loop unsuccessfully to .insert each entry for each index. I just started scripting python 3 days ago so I apologize if I'm overlooking something basic. Any help would be appreciated, thanks.
eval(). Do not useeval()in production code. It's very dangerous and especially for untrusted input like files.array = [f]addarray = array[0]and tell me if that works please"["and'"'to be output, since those are the first and second characters in the file respectively.type(f)then?