TypeError:object()不带参数 [英] TypeError: object() takes no parameters
本文介绍了TypeError:object()不带参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的代码生成以下错误:TypeError: object() takes no parameters
My code generates the following error: TypeError: object() takes no parameters
class Graph(object):
def vertices(self):
return list(self.__graph_dict.keys())
if __name__ == "__main__":
g = { "a" : ["d"],
"b" : ["c"],
"c" : ["b", "c", "d", "e"],
"d" : ["a", "c"],
"e" : ["c"],
"f" : []
}
graph = Graph(g)
print("Vertices of graph:")
print(graph.vertices())
有没有办法解决这个问题?
Is there a way I can solve this?
推荐答案
您的Graph类在__init__
上不接受任何参数,因此在您调用时:
Your Graph class takes no arguments on __init__
therefore when you call:
图=图(g)
graph = Graph(g)
您收到一个错误,因为Graph不知道如何处理'g'. 我想您可能想要的是:
You get an error because Graph doesn't know what to do with 'g'. I think what you may want is:
class Graph(object):
def __init__(self, values):
self.__graph_dict = values
def vertices(self):
return list(self.__graph_dict.keys())
这篇关于TypeError:object()不带参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文