Python: How to call an instance method from a class method of the same class

前端 未结 2 905
渐次进展
渐次进展 2020-12-16 16:15

I have a class as follows:

class MyClass(object):
    int = None
    def __init__(self, *args, **kwargs):
        for k, v in kwargs.iteritems():
                    


        
2条回答
  •  轮回少年
    2020-12-16 17:06

    No, you can't and shouldn't call an instance method from a class without an instance. This would be very bad. You can, however call, a class method from and instance method. Options are

    1. make get_param a class method and fix references to it
    2. have __init__ call get_param, since it is a instance method

    Also you may be interested in an AttrDict since that looks like what you are trying to do.

提交回复
热议问题