[英]Expected an indented block, python
Hello can someone fix it I tried to find solution online but nothing work.您好,有人可以解决它吗?我试图在网上找到解决方案,但没有任何效果。
Python Version: 3.7.9 Python 版本:3.7.9
if engine == "example1":
search = example1(engine)
request = partial(search.search_for, string)
all = p.map(request, pages)
elif engine == "example2":
filepath = "list.txt"
with open(filepath) as fp:
line = fp.readline()
count = 1
while line:
search = example2(engine)
request = partial(search.search_for, line.strip())
all = p.map(request, pages)
line = fp.readline()
count += 1
input(" press close to exit ")
It appears that the biggest issue is with lines immediately following your with
statement.似乎最大的问题是紧跟在您的with
语句之后的行。 Those should be indented to be part of the context manager scope.这些应该缩进成为上下文管理器 scope 的一部分。
elif engine == "example2":
filepath = "list.txt"
with open(filepath) as fp:
line = fp.readline() # <--- note indent
count = 1 # <--- note indent
while line:
search = example2(engine)
request = partial(search.search_for, line.strip())
all = p.map(request, pages)
line = fp.readline()
count += 1
Here you have 2 intent mistakes.copy this code and try it这里有 2 个意图错误。复制此代码并尝试
if engine == "example1":
search = example1(engine)
request = partial(search.search_for, string)
all = p.map(request, pages)
elif engine == "example2":
filepath = "list.txt"
with open(filepath) as fp:
line = fp.readline()
count = 1
while line:
search = example2(engine)
request = partial(search.search_for, line.strip())
all = p.map(request, pages)
line = fp.readline()
count += 1
input(" press close to exit ")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.