Getting NameError when calling function in constructor

前端 未结 4 723
粉色の甜心
粉色の甜心 2021-01-21 07:31

I ran the code below, by calling the function in the constructor

First --

>>> class PrintName:
...    def __init__(self, value):
...      self.         


        
4条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-21 07:44

    Instead of

    printName(self._value)
    

    you wanted

    self.printName(self._value)
    

    It probably worked the first time because you had another function printName in a parent scope.

提交回复
热议问题