[英]Python is telling me an indention is expected where I put one
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. 我很感激任何答案。
Further, is def start()
actually indented in your file? 另外, def start()
实际上是在文件中缩进的吗? It isn't indented in this question, and that's what Python seems to be complaining about. 它没有缩进这个问题,这就是Python似乎在抱怨的东西。
Check that whitespace is consistent (ie mixing tabs and spaces?). 检查空格是否一致(即混合制表符和空格?)。
If your editor supports, I suggest to make it expand all tabs to (4) spaces. 如果您的编辑器支持,我建议将所有选项卡扩展为(4)空格。 This avoids such confusion, also when copy-pasting code. 这样可以避免这种混淆,也就是在复制粘贴代码时。
In vim: 在vim中:
:se tabstop=4 shiftwidth=4 expandtab
:%retab
Are you sure there is a tab
character in that position? 你确定那个位置有一个tab
符吗? Try open it with vi
and add yourself the tab
just to check is fine. 尝试用vi
打开它并添加tab
只是为了检查是否正常。
Looks like it expects def start():
to be indented. 看起来它期望def start():
缩进。 What does the code look like before that? 在那之前代码是什么样的?
Try looking at the code just before that line. 尝试查看该行之前的代码。 Is there an unfinished block (line ending with :
)? 是否有未完成的块(行以:
结尾)? If yes, put something in that block – a pass
statement will do. 如果是的话,在该块中添加一些东西 - pass
语句就可以了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.