为什么jupyter笔记本会抛出IndentationError?

时间:2017-07-09 14:31:45

标签: python jupyter-notebook

我使用jupyter notebook有一些非常奇怪的行为。

这是一个基本的python函数:

def configure_wg_drem(data_file_pattern): return data_file_pattern

configure_wg_drem('Adult/Adult_*.txt')

给了我:

'Adult/Adult_*.txt'

但与普通python格式相同的功能:

def configure_wg_drem(data_file_pattern): 
    return data_file_pattern

configure_wg_drem('Adult/Adult_*.txt')

引发错误:

  File "<ipython-input-97-c97da191fc79>", line 29
    return data_file_pattern
         ^
IndentationError: expected an indented block

有人对此有解释吗?

我尝试使用jupyter笔记本提供的自动缩进,当你使用冒号并按Enter键时,单个制表符以及四个空格而不是制表符。都具有相同的结果。

我还尝试重新启动jupyter notebook并获得相同的行为。

1 个答案:

答案 0 :(得分:1)

您的代码中可能包含混合的TAB和空格。

我建议你只使用空格。