NEWBIE: Sub-Classes

E

engsolnom

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,280
Latest member
BGBBrock56

Latest Threads

Top