Python 告诉我在我放置的地方应该有一个缩进

发布于 2024-12-09 23:32:26 字数 492 浏览 1 评论 0原文

好的,这是脚本的一部分:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

雄赳赳气昂昂 2024-12-16 23:32:26
  • 确保您没有混合制表符和空格进行缩进
  • 您的字符串缺少结束引号

此外,def start() 实际上在您的文件中缩进了吗?这个问题没有缩进,这就是 Python 似乎抱怨的地方。

  • Make sure you aren't mixing tabs and spaces for indentation
  • Your string is missing a closing quote

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.

慕烟庭风 2024-12-16 23:32:26

看起来它需要缩进 def start(): 。在此之前的代码是什么样的?

Looks like it expects def start(): to be indented. What does the code look like before that?

谁的新欢旧爱 2024-12-16 23:32:26

检查空白是否一致(即混合制表符和空格?)。

如果您的编辑器支持,我建议将所有选项卡扩展为 (4) 个空格。这可以避免这种混乱,在复制粘贴代码时也是如此。

在维姆中:

:se tabstop=4 shiftwidth=4 expandtab
:%retab

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:

:se tabstop=4 shiftwidth=4 expandtab
:%retab
姐不稀罕 2024-12-16 23:32:26

您确定该位置有一个 tab 字符吗?尝试使用 vi 打开它并添加自己的 tab 只是为了检查是否正常。

Are you sure there is a tab character in that position? Try open it with vi and add yourself the tab just to check is fine.

顾冷 2024-12-16 23:32:26

尝试查看该行之前的代码。是否有未完成的块(以 : 结尾的行)?如果是,请在该块中放入一些内容 - 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 – a pass statement will do.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文