Python 告诉我在我放置的地方应该有一个缩进
好的,这是脚本的一部分:
def start():
print "While exploring the ruins of a recently abandoned castle you stumble apon the entrance to what appears to be a dungeon. You are carrying on you a...
我不断收到错误
user@ubuntu:~/Documents/python$ python dungeon.py
File "dungeon.py", line 533
def start():
^
IndentationError: expected an indented block
,我知道这可能是显而易见的,但有人知道我做错了什么吗?我尝试替换缩进 仅包含空格和制表符,但它仍然给我这个错误。我很感激任何答案。
OK, here's a piece of the script:
def start():
print "While exploring the ruins of a recently abandoned castle you stumble apon the entrance to what appears to be a dungeon. You are carrying on you a...
I keep getting the error
user@ubuntu:~/Documents/python$ python dungeon.py
File "dungeon.py", line 533
def start():
^
IndentationError: expected an indented block
I know this is probably obvious but does anyone have any clue as to what I'm doing wrong hear? I tried replacing the indent
with spaces only and tabs only but it still gives me this error. I appreciate any answers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
此外,
def start()
实际上在您的文件中缩进了吗?这个问题没有缩进,这就是 Python 似乎抱怨的地方。Further, is
def start()
actually indented in your file? It isn't indented in this question, and that's what Python seems to be complaining about.看起来它需要缩进
def start():
。在此之前的代码是什么样的?Looks like it expects
def start():
to be indented. What does the code look like before that?检查空白是否一致(即混合制表符和空格?)。
如果您的编辑器支持,我建议将所有选项卡扩展为 (4) 个空格。这可以避免这种混乱,在复制粘贴代码时也是如此。
在维姆中:
Check that whitespace is consistent (i.e. mixing tabs and spaces?).
If your editor supports, I suggest to make it expand all tabs to (4) spaces. This avoids such confusion, also when copy-pasting code.
In vim:
您确定该位置有一个
tab
字符吗?尝试使用vi
打开它并添加自己的tab
只是为了检查是否正常。Are you sure there is a
tab
character in that position? Try open it withvi
and add yourself thetab
just to check is fine.尝试查看该行之前的代码。是否有未完成的块(以
:
结尾的行)?如果是,请在该块中放入一些内容 -pass
语句即可。Try looking at the code just before that line. Is there an unfinished block (line ending with
:
)? If yes, put something in that block – apass
statement will do.