我不知道为什么我收到一个错误消息,当我运行的addItem()说:我不断收到这个错误,当我运行我的功能: - 语法错误:意外的EOF在解析
SyntaxError: unexpected EOF while parsing
我有我所有的阅读和写作文件都关闭了,我正在使用raw_input
函数。我认为我的readfrom()函数有问题,但我不知道究竟是什么。
import ast
def writeTo():
itemx=",".join(map(str,itemx))
with open("ListItemz.txt","a") as filewrite:
filewrite.write(str(itemx)+"\n")
filewrite.close()
def readfrom():
fileread=open("ListItemz.txt","r")
fr=fileread.readlines()
fr=fr[len(fr)-1]
itemx=list(ast.literal_eval(fr))
fileread.close()
itemx=[]
def addItem():
global itemx
if itemx==[]:
itemx=[]
else:
"""
about to read file:
"""
readfrom()
dowhile="y"
while dowhile =="y":
item=raw_input("please enter item discription, or barcode No. ")
if itemx!=[]:
for y in itemx:
if item==y[0] or item==y[1]:
raise TypeError("This Item is already added")
case=int(raw_input("Enter how much holds in one (1) case: "))
caseNo=int(raw_input("how many cases are there? "))
for i in stockList():
if item==i[1] or item==i[0]:
itemx+=[[i[0],i[1],case,caseNo]]
print "ITEM ADDED"
dowhile=raw_input("Do you want to add another?(Y/N) ")
"""
about to write itemx to a file:
"""
writeTo()
return itemx
'fr = fr [len(fr)-1]'的价值是什么?像ast.literal_eval(“(1,”)''可以产生相同的错误,发布完整的错误追溯。 –
我没有得到这样的错误发布在这里的代码。EOF错误意味着Python期待的东西*其他*但是你没有提供它,这是*整个*文件吗? –
你不需要'关闭()'已经被'with'构造关闭的文件。 – TigerhawkT3