def sum_list(name):
num = []
with open(name) as file:
for line in file:
line = line.strip()
num.append(int(line))
sum = 0
for i in num:
sum = sum + i;
print("Sum of numbers : "+str(sum))
name = input("Enter path of file: ")
sum_list(name)
它给我错误
invalid literal for int() with base 10: 'def sum_list(name):'
回溯(最近通话最近一次):
文件“”,第1行,在 runfile('C:/Users/Ghost/Documents/Anaconda/untitled0.py',wdir ='C:/ Users / Ghost / Documents / Anaconda')
文件“ D:\ New 文件夹\ lib \ site-packages \ spyder_kernels \ customize \ spydercustomize.py”, 运行文件中的第704行 execfile(文件名,命名空间)
文件“ D:\ New 文件夹\ lib \ site-packages \ spyder_kernels \ customize \ spydercustomize.py”, execfile中的第108行 exec(compile(f.read(),文件名,'exec'),命名空间)
文件“ C:/Users/Ghost/Documents/Anaconda/untitled0.py”,第12行,在 sum_list(名称)
文件“ C:/Users/Ghost/Documents/Anaconda/untitled0.py”,第6行,在 sum_list num.append(int(line))
ValueError:以10为底的int()的无效文字:'def sum_list(name):'