NEWBIE: Sub-Classes
engsolnom at ipns.com
engsolnom at ipns.com
Tue Dec 30 20:40:03 EST 2003
I'm a bit baffled. In the code below, I expected that the import in tst_sub.py would expose all the
contents of dir_a.py. But, as it turns out...it doesn't.
I can understand (I think) why B has to be qualified in class A(dir_a.B), but why is dir_a.B.class_B
required?
Also, how can I expose self.B_self to A?
Thanks......Norm
DIRECTORY DIRA: DIR_A.PY:
var = 13
class B:
class_B = 21
def __init__ (self):
self.B_self = 31
def B_meth_1(self):
self.class_B = 19
DIRECTORY MYFILES: TST_SUB.PY:
import dir_a
print dir_a.var
class A(dir_a.B):
def __init__ (self):
self.B_meth_1() # Run the base class B method
self.class_a = self.class_B # Gets the value in B_meth_1
self.class_aa = dir_a.B.class_B # Gets B's 'static' var
print self.class_a
print self.class_aa
# Prints 13
obj_1 = A() # Prints 19, 21
obj_2 = A() # Prints 19, 21 showing A.__init__() was run again
More information about the Python-list
mailing list