I want to store the values that I splitted in an array. I've tried printing it outside of the for loop but it just gives me a single value.
Date Close/Last Volume Open High Low
10/06/2021 $142 83221120 $139.47 $142.15 $138.37
def stocks(file) :
try:
fh = open(file, 'r')
except IOError:
print("error opening file ....", file)
else:
arr = {}
records = fh.readlines()
for record in records:
fields = record.split(',')
arr = fields[2]
print(arr)
fh.close()
arris adict. What isarr = fields[2]supposed to do? Did you meanarr[fields[2]] = fields? (Also, you probably want to have a look at thecsvmodule.)list.append()method.