Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed last year.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(2)
也许尝试一些带有可见空白的文本编辑器?在我打开 TextMate 中的“显示不可见内容”之前,我一直遇到过这样讨厌的错误。
Perhaps try some text editor with visible white-space? I've had pesky bugs like this until I turn on "Show Invisibles" in TextMate.
OP 提到的帖子(在评论中 - 不是一个好主意,@gheddo!编辑你的 Q!),此处,正是此代码(我仅复制并粘贴两个相关的行):
看到问题了吗?第二行无缩进!因此,语法错误:函数体(以及其他复合语句体)必须在Python中缩进。
几乎没有必要让我们阅读该代码,您知道...该代码的作者 John Melbourne 在该线程的下一篇文章中说道,我引用:
因此,这正是您必须做的 - 重新缩进函数体、
if
和while
语句,如果您需要为此目的,请参阅 Flavio Bernardotti 的代码。另外,将来,我强烈建议您在主题中至少阅读一篇帖子(如果阅读整个主题对您来说工作量太大......;-)...
The post the OP referred to (in a comment -- not a great idea, @gheddo! edit your Q instead!), here, has exactly this code (I'm copying and pasting only the two relevant lines):
see the problem? No indentation for the second line! Therefore, a syntax error: function bodies (and other bodies of compound statements) must be indented in Python.
It was hardly necessary to send us reading that code, you know... the code's author, John Melbourne, in the very next post in this thread says, and I quote:
So that's exactly what you have to do -- re-indent the function bodies,
if
andwhile
statements, and refer to Flavio Bernardotti's code if you need to for this purpose.Also, in the future, I would strongly recommend you read at least one post later in a thread (if reading the whole thread is too much work for you...;-)...