Python: How To Call An Instance Method From A Class Method Of The Same Class
I have a class as follows: class MyClass(object): int = None def __init__(self, *args, **kwargs): for k, v in kwargs.iteritems(): setattr(self, k, v)
Solution 1:
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
- make
get_param
a class method and fix references to it - have
__init__
callget_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.
Post a Comment for "Python: How To Call An Instance Method From A Class Method Of The Same Class"