Python参数奇怪的不匹配

问题描述 投票:2回答:1

在测试一些代码时,出现错误:

TypeError:Breadth_first_search()从2到3个位置参数,但给出了4个位置参数

函数声明的参数位看起来像这样:

def breadth_first_search(self, id: int, level=None)

通话看起来像这样:

tree.breadth_first_search(parent_id)

据我所知,这应该是正确的。我不知道为什么它将一个参数(或两个参数,包括self)解释为四个。我缺少什么东西吗?

-

为了完整性,这里是回溯:

Traceback (most recent call last):
  File "test.py", line 4, in <module>
    tree = FeatureQuery.load_feature_tree("general", inventory)
  File "D:\Speechcraft\Python\core\ling_query.py", line 201, in load_feature_tree
    FeatureQuery.load_feature_node_recursive(feature_inventory, tree, results, l)
  File "D:\Speechcraft\Python\core\ling_query.py", line 221, in load_feature_node_recursive
    parent = tree.breadth_first_search(parent_id)
  File "D:\Speechcraft\Python\core\phonological_units.py", line 37, in breadth_first_search
    return self.breadth_first_search(self, id, next_level)
TypeError: breadth_first_search() takes from 2 to 3 positional arguments but 4 were given
python parameter-passing
1个回答
0
投票
原来是一个愚蠢的错误。我不小心将

self作为参数包含在递归调用中。感谢转到user2357112 supports monica

© www.soinside.com 2019 - 2024. All rights reserved.