简体   繁体   English

制表符和空格的用法不一致吗?

[英]What is there an inconsistent use of tabs and spaces?

The error reads: 该错误显示为:

dhcp-169-233-163-147:Desktop juliushamilton$ python3 printTrie.py
  File "printTrie.py", line 16
    matchbuild(daughter, next(base))
                                                                           ^
TabError: inconsistent use of tabs and spaces in indentation

My code reads: 我的代码是:

def matchbuild(node, base):
    match = False
    if base == False:
       return
    for daughter in node.daughters:
        if base == node.edge:
            match = True 
            matchbuild(daughter, next(base))
    if match == False:
       trie.append(Node(node, [], base))
       matchbuild(node, base)

I wanted to put the for/if section as a one-liner, but the execution also raised an error here. 我想将for / if部分作为单行,但是执行过程在这里也引发了错误。 What could be wrong with the spacing? 间距怎么了?

The issue is as the stacktrace indicates, you are using either tabs or spaces at other places for indentation , but in the line - 问题是正如stacktrace所指示的那样,您在其他位置使用制表符或空格进行缩进,但在该行中-

matchbuild(daughter, next(base))

You are using the opposite thing (like you may be using spaces to indicate indentation in other lines , but then you used tabs to indicate the indentation for this line. In Python 3.x , you cannot mix tabs and spaces , you have to use a consistent thing throughout your script. I believe it is recommended to use 4 spaces to indicate a level of indentation. 您正在使用相反的东西(例如您可能使用空格来指示其他行的缩进,但是随后您使用了制表符来指示该行的缩进。在Python 3.x中,您不能将制表符和空格混合使用,我认为建议您使用4个空格来表示缩进级别。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM