2024-09-28 01:28:02 发布
网友
我是python新手,遇到了这个List is not callable错误。 我应该怎么做来防止这种情况发生?谢谢
List is not callable
def PrintTxt(src, beg, end): with open(src, 'r') as f1: srctxt = f1.readlines() for line in srctxt(beg, end): print(line) Filepath = 'C:\test.txt' PrintTxt(Filepath,1,5)
你似乎不知道正确的Python slice notation。之后:
srctxt = f1.readlines() # now srctxt is a list
您可以对结果list进行切片,如下所示:
list
for line in srctxt[beg:end]: # ....
你似乎不知道正确的Python slice notation。之后:
您可以对结果
list
进行切片,如下所示:相关问题 更多 >
编程相关推荐