【发布时间】:2018-07-29 13:10:54
【问题描述】:
我收到的错误消息是 IndexError: tuple index out of range。 这很奇怪,因为我在这段代码中没有使用元组,我应该如何解决它?
import os
import glob
import pathlib
lista = []
word = input("Write searchword: ")
file_path = input("Write pathway: ")
for path, directories, files in os.walk(file_path):
count = 0
if os.path.isdir(file_path):
for p in pathlib.Path(file_path).glob("."):
with open(p) as user:
for line in user:
if word in line:
count += 1
if count > 0:
new = str(p).split("'")
lista.append(new)
lista.append(count)
lista.append("\n")
name = ' '.join(str(w) for w in lista)
print (name)
【问题讨论】:
-
请添加完整的回溯,以便我们查看错误的来源。
标签: python python-3.x python-2.7 python-requests