我一直在我的程序中收到此错误,我不知道如何修复它。这是错误发生的地方。
def check_file():
for read in range(6):
length = len(linecache.getline('status.py', read))
f = linecache.getline('status.py', read)[0:length-1]
print (f)
if read >= 6:
print("5")
else:
file[read-1][1] = f
return file
def change_state(change_till, state): # changes tills' status
global file
data = ''
status = check_file()
status[change_till-1][1] = state
file = open('status.py', 'w')
file.write(status[0][1]+'\n'+status[1][1]+'\n'+status[2][1]+'\n'+status[3][1]+'\n'+status[4][1])
file.close()
return state
我运行代码并出现此错误
Traceback (most recent call last):
File "C:\Users\rhysj\OneDrive\Documents\Rhys Morgan Jones\My Projects\Coding\Python\Months\December 2016\aldi\till.py", line 151, in <module>
start()
File "C:\Users\rhysj\OneDrive\Documents\Rhys Morgan Jones\My Projects\Coding\Python\Months\December 2016\aldi\till.py", line 144, in start
state = check_status(this_till-1)
File "C:\Users\rhysj\OneDrive\Documents\Rhys Morgan Jones\My Projects\Coding\Python\Months\December 2016\aldi\till.py", line 58, in check_status
status = check_file()
File "C:\Users\rhysj\OneDrive\Documents\Rhys Morgan Jones\My Projects\Coding\Python\Months\December 2016\aldi\till.py", line 21, in check_file
file[read-1][1] = f
TypeError: '_io.TextIOWrapper' object is not subscriptable.
有谁知道为什么会发生这种情况以及如何解决这个问题?