-2

I'm new to python and I can't get instance of the class below Which is in a python file named "util.py":

...
class Stack:
    def __init__(self):
        self.list = []
...

And I'm trying to construct an instance of the aforementioned class in another python file named "Search.py";Here's the code :

def depthFirstSearch(problem):

   from util import Stack

   path = [] #list used to return the desired actions

   DFSstack = Stack()

There's really nothing more in my code believe me!:) But I get this error : TypeError: 'NoneType' object is not iterable

Help me out please!

4

2 回答 2

1

你不需要__init__直接打电话;打电话给班级

>>> class Stack:
...     def __init__(self):
...         self.list = []
... 
>>> DFSstack = Stack()

然后__init__将自动调用初始化方法。

于 2013-10-11T09:59:02.807 回答
0

为什么不让 Stack 从列表中继承?它的工作原理几乎与列表相同,但您可以向其中添加自己的方法。

class Stack(list):
    pass
于 2013-10-11T10:33:58.840 回答