I am having to read in from a file with lines in format '(Buy or Sell) (int representing number of stocks) (cost of stock)\n' and this was my solution on how to create a 2d array to access the different stuff later in the project.
with open(inputFile, 'r') as f:
purchases = f.readlines()
for line in purchases:
tList.append(line).rstrip('\n'))
for lineNum in range(0,len(tList)-1):
tList[lineNum].split()
#0 = 'Buy' or 'Sell', 1 = number of stocks, 2 = price per stock
tList[lineNum][1] = eval(tList[lineNum][1])
tList[lineNum][2] = eval(tList[lineNum][2])
When I run my code, this is the error message I get.
File "project4.py", line 187, in <module>
main()
File "project4.py", line 103, in main
tList[lineNum][1] = eval(tList[lineNum][1])
File "<string>", line 1, in <module>
NameError: name 'u' is not defined
I assume that the .split function is splitting my line at every character and this is why it gets 'u' from 'Buy' I think the B is stored in tList[lineNum][0] but it cant eval the 'u'. I have no idea how to fix this and any help would be appreciated.