python - Unndent 不匹配任何外部缩进级别
问题描述
尝试运行以下 python 代码,我收到缩进错误:
from urllib.request import urlopen
def fetch_words():
with urlopen('http://sixty-north.com/c/t/txt') as story:
story_words = []
for line in story:
line_words = line.decode('utf-8').split()
for word in line_words:
story_words.append(word)
return story_words
def print_words(story_words):
for word in story_words:
print(word)
def main():
words = fetch_words()
print_words(words)
if __name__ == '__main__':
main()
解决方案
检查此缩进是否适合您
from urllib.request import urlopen
def fetch_words():
with urlopen('http://sixty-north.com/c/t/txt') as story:
story_words = []
for line in story:
line_words = line.decode('utf-8').split()
for word in line_words:
story_words.append(word)
return story_words
def print_words(story_words):
for word in story_words:
print(word)
def main():
words = fetch_words()
print_words(words)
if __name__ == '__main__':
main()
推荐阅读
- reactjs - ABP React Mobile 框架中的空键
- python - 尝试从 python 中的网站下载 .csv
- c# - Blazor 未处理的异常呈现组件
- python - 将两个 numpy 数组与基于两个数组的方程组合
- python - 使用两个输入作为字符串构建连体网络
- python - Matplotlob set_position() 不适用于带有 constrained_layout 的子图
- python - 我只需要所选选择的结果,但它会显示所有其他结果以及任何选择
- java - 为火棒制作应用程序,但按钮单击和悬停不起作用
- locust - 如何在 Locust 中为 FastHTTPUser 方法配置代理
- .net-core - 如何创建 ApiAuthorizationDbContext 的 Mock(Moq) 对象