python方法调用类 __call__方法

本文共有444个字,关键词:

问题:方法中如何调用另一个类中__call__方法?

方法:

class foo(object):
    def __init__(self):
        self.name = 'python'

    def __call__(self, *args, **kwargs):
        print('hello%s'%self.name)

def run():
    instance = foo()
    instance()
    a = instance
    print dir(a)

参考:

https://blog.csdn.net/qq_21583139/article/details/119720698
版权声明:本文为作者原创,如需转载须联系作者本人同意,未经作者本人同意不得擅自转载。
添加新评论
暂无评论