Can I pass class method as and a default argument to another class method

前端 未结 3 942
耶瑟儿~
耶瑟儿~ 2021-01-05 11:38

I want to pass class method as and a default argument to another class method, so that I can reuse the method as a @classmethod:

@classmethod
cl         


        
3条回答
  •  南方客
    南方客 (楼主)
    2021-01-05 11:49

    Default argument values are computed during function definition, not during function call. So no, you can't. You can do the following, however:

    def func2(self, aFunc = None):
        if aFunc is None:
            aFunc = self.func1
        ...
    

提交回复
热议问题