Why does 'return self' return None?

前端 未结 4 1909
我寻月下人不归
我寻月下人不归 2021-01-25 06:49

I\'m trying to get the top node of a chain in getTopParent(). When I print out self.name, it indeed prints out the name of the parent instance; however

4条回答
  •  太阳男子
    2021-01-25 07:43

    use return in

    else:
        print( "checking %s" % self.name )
        return self.owner.getTopParent()
    

    as None is the default return Value, then it'll output:

    checking child3
    checking child2
    checking child1
    Got top: parent
    <__main__.A instance at 0xb77a628c>
    

提交回复
热议问题