为什么我在这里得到“ IndentationError:期望缩进的块?”

问题描述 投票:-5回答:1

标题说。我正在使用Pythin 3 Jupyter笔记本。

代码:

image[0].save(out_fname, save_all = True, quality=100, append_images = images[1:])

错误:

File "<ipython-input-22-976c7de2f57a>", line 8
    image[0].save(out_fname, save_all = True, quality=100, append_images = images[1:])
        ^
IndentationError: expected an indented block

编辑:这是单元格的其余部分。

image = []
for i in range(min_range, max_range + 1):

image[0].save(out_fname, save_all = True, quality=100, append_images = images[1:])

[双重编辑:尝试在最后一行上加上标签会导致“列表索引超出范围”错误。

python indentation
1个回答
0
投票

Python要求缩进作为其语法的一部分。声明for循环时,缩进告诉Python该代码属于该循环。

更改

for i in range(min_range, max_range + 1):
image[0].save(out_fname, save_all = True, quality=100, append_images = images[1:])

to

for i in range(min_range, max_range + 1):
    image[0].save(out_fname, save_all = True, quality=100, append_images = images[1:])

应解决您的问题。

您对image[0]的调用会产生错误,因为image = [],因此不包含索引0。

© www.soinside.com 2019 - 2024. All rights reserved.