python idle on Enter 时缩进出错

Indentation goes wrong in python idle on Enter

当我输入上一行时,我的空闲缩进转到右侧,如屏幕截图所示(在 python 建议的缩进处标记为黄色)。 python 3.x 和 2.x 中的相同代码会出现相同的问题。任何帮助表示赞赏。

注意:如果我选择使用 python 建议的缩进,则会出现缩进错误。

如果我注释掉代码,问题就会消失

self.directory = os.path.abspath(os.path.dirname(file)

您忘记在 os.path.abspath 调用中关闭括号。 IDLE 认为您是故意这样做的,它会将缩进与左括号对齐,这是格式化跨多行语句的常用方法。