6
votes

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?

1

1 Answers

14
votes

Your Graph class takes no arguments on __init__ therefore when you call:

graph = 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())