TypeError: object () does not accept 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 any way to solve this?

+5
source share
1 answer

Your Graph class does not accept arguments on __init__ , so when called:

graph = Graph (g)

You get an error because Graph does not know what to do with 'g'. I think you might want:

 class Graph(object): def __init__(self, values): self.__graph_dict = values def vertices(self): return list(self.__graph_dict.keys()) 
+11
source

Source: https://habr.com/ru/post/1207475/


All Articles