I have a base class like this:
class base(object):
name = ""
def __init__(self,name):
self.user =user
def context(self,value):
return {}
Instead of this i created an another subclass and override this above “context” method:
class override(base):
name = "New class"
def context(self, value):
a = []
a = "hello","b"
return a
I want to create a plugins, all they have are different definitions (different value of list will return) for context method. So i want to do this by putting override functionality.
When i call this base.context function from an another file. Following things should be happen:
-
The list i.e
"a"(in override context method) should return it’s value to base context method first. -
After getting a value from
override.contextmethod, base.context will return that value to from where it’s called after making some changes into it.
But, When i call this base.description method it will return a value directly from override.description method. So i am not able to make that changes into it 🙁
A few things in you question are a little confusing, but I think that what you want is something like this example (python2.7):
The you can do the following:
However, calling these methods on
basegives different results:Its not entirely clear if this is what you want though, because you refer to
base.contextgetting a value fromoverride.context, whereas it normally happens the other way around. The same goes foroverride.description. If you really wantbase.contextto get a value fromoverride.contextthis can be done throughbase.__subclasses__(), but you would have to deal with all subclasses ofbase, and this sort of usage is extremely uncommon (and usually undesirable).