Python:我在函数中的注释的最后3个引号(“”)上得到“缩进块”错误。这是怎么回事? [英] Python: I'm getting an 'indented block' error on the last 3 quotes (""") of my comments under functions. What's up?

查看:635
本文介绍了Python:我在函数中的注释的最后3个引号(“”)上得到“缩进块”错误。这是怎么回事?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

超级奇怪,不是吗?违规代码:

Super odd, no? The offending code:

def main():
"""
main function
"""
    # Argument handling

    args = sys.argv[1:]
    if not args:
        print "usage is: ...

第三个引用是我得到常见的缩进错误:

The third quote is where I get the usual indentation error:

>>>Import someScript
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "someScript.py", line 24
    """
      ^


b $ b

如果我删除注释(显然我不想),那么要定义的下一个函数在其注释的相同位置获得相同的错误。如果我删除函数中的所有注释,错误消失。

If I delete the comments (obviously I don't want to) then the next function to be defined gets the same error, at the same location of its comments. If I delete all comments from functions, the error goes away.

我不明白!为什么期望缩进?我在Komodo编辑部分,因为它不允许你混合空格和制表符,但只是为了确保我做了一个搜索,并且,确定,没有friggin选项卡。不是说,如果有的话,它会有意义。

I don't understand! Why expect an indent there? I'm writing in Komodo Edit partially because it doesn't let you mix spaces and tabs, but just to be sure I did a search and, sure enough, there are no friggin tabs. Not that it would make sense anyway if there were.

古茹是什么?

推荐答案

您需要将文档字符串与函数的块一起缩进。

You need to indent the docstring along with the block for your function.

每个冒号()后面必须紧跟一个缩进块。

Every colon (:) must be immediately followed by an indented block.

这篇关于Python:我在函数中的注释的最后3个引号(“”)上得到“缩进块”错误。这是怎么回事?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆