2017-07-09 120 views
0

我有一些非常奇怪的行为,使用jupyter notebook为什么jupyter笔记本投掷IndentationError?

这是一个基本的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并得到相同的行为。

+0

你确定中间没有不可打印的字符吗?创建一个新的单元格,写出'def foo(bar):\ nreturn bar',尝试并将其变形,直到它看起来像您的原始示例。 – user2722968

回答

1

您可能在代码中混合了TAB和空格。

我建议你只用空格。