Skip to content
Advertisement

Module object is not callable when using defaultdict package not working in PyCharm [closed]

I am trying to implement DFS Graph in python and I am newbie I am Python programming. I import defaultdict package in this code.I face this error and I was not figure out this error:

Traceback (most recent call last): File “/Users/abdullahsheikh/PycharmProjects/Implement_dfs/main.py”, line 26, in DFS_graph=DFS_() File “/Users/abdullahsheikh/PycharmProjects/Implement_dfs/main.py”, line 6, in init self.graphlist = defaultdict(self) TypeError: ‘module’ object is not callable

code sample is :

JavaScript

Advertisement

Answer

There are multiple issues here.

  1. from collections import defaultdict instead of import defaultdict

  2. self.graphlist = defaultdict() instead of self.graphlist = defaultdict(self)

  3. Not sure what the methods are supposed to do. AddEdge should probably be something like:

    JavaScript

    The other methods need a clean up, too.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement