Imagine I have a class A
class A(object):
def __init__(self, x, y)
self.x = x
self.y = y
and then I define a class B that is initialized by A (rather than take A as its base) and other parameters
class B(object):
def __init__(self, a):
if isinstance(a, A):
self.a = a
The question is, suppose A has a gigantic amount of variables defined and shall be referred to in B frequently, is it possible to make B aware of those variables in A, so that in B I can do
self.x
rather than
self.a.x
?
I am aware this automatic inheritable of variables is kinda dangerous and even could be destructive, but typing many extra self.a.x looks a little clunky. Having the option to turn on this inheritance temporarily or in small snippets of code should be useful.
EDIT
__dict__ brings up essentially everything, including methods and functions, possible to keep only numerical variables?
You can write:
Whenever you access an attribute of
B, it will check ifahas that attribute. If so, it’ll return that instead. If not, it will lookup the attribute inBitself.