简体   繁体   English

Python告诉我,在我放置一个凹槽时,预计会有一个缩进

[英]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. 我很感激任何答案。

  • 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? 另外, 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.

相关问题 Python函数告诉我,当我只发送一个时,我发送了两个参数 - Python function telling me I sent two arguments when I only sent one Python告诉我66 &lt;= 17 - Python is telling me 66 <= 17 为什么 pipenv 告诉我 python 的错误版本? - Why is pipenv telling me the wrong version of python? 在不告诉我的情况下返回true或false……python 3 - Returning true or false without me telling it to… python 3 VS Code 一直告诉我我没有 Python……但我有 - VS Code keeps telling me I don't have Python… but I do 为什么系统告诉我我的系统中没有 Python 3.10? - Why is the system telling me that I don't have Python 3.10 in my system when I do? for i in range 为什么这告诉我有语法错误? - for i in range why is this telling me there is a syntax error? 嗨,我对 python pipreqs 有一些问题。 它一直告诉我用法而不是创建正确的文件 - Hi, I have some issue with the python pipreqs. It keeps telling me the usage instead of creating the right file 我试图从今天的日期中减去一个日期,但它告诉我 python 不支持操作数类型 - I am trying to subtract a date from todays date but it is telling me the operand type is unsupported in python Python IDLE中的缩进问题 - Indention issue in Python IDLE
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM