I'm having trouble understanding what is going on to make a difference in static object and member objects (those created in constructor).
The following will run the overridden get():
class A(object):
class B(object):
def __init__(self, initval=None, name='var'):
self.val = initval
self.name = name
def __get__(self, obj, objtype):
print('B Retrieving', self.name)
return self.val
b = B(10, 'var "b"')
But, if I pull b in to the constructor it does not:
class A(object):
class B(object):
def __init__(self, initval=None, name='var'):
self.val = initval
self.name = name
def __get__(self, obj, objtype):
print('B Retrieving', self.name)
return self.val
def __init__(self)):
self.b = A.B(10, 'var "b"')
I really want to make this work in the latter and maybe this isn't the right way to do it.
Can someone please explain what is going on here in a call to print(a.b)
where a = A()
?
Also, is there a way to have print(a.b)
call a member function from b?