Newbie inheritance question.

bwobbones bwobbones at
Sun Jan 16 09:08:13 EST 2005

Hi all,

  I'm a java programmer struggling to come to terms with python - bear 
with me!

  I'm trying to subclass a class, and I want to be able to see it's 
attributes also.  Here are my classes:
class one:
    def __init__(self):
        print "one"
        self.testVar = 1

    def printHello(self):
        print "hello"
from one import one

class two(one):
    def __init__(self):
        print "two"

    def printTestVar(self):
        print "testVar: " + str(self.testVar)

and the driver to make it work:
from two import two

class driver:
    def go(self):
        print "driver"
        self.two = two()

if __name__ == '__main__':
    d = driver()

the "self.two.printTestVar()" call doesn't work: shouldn't have 
access to all of it's parents attributes?  In java I would make the 
testVar protected so it's children could see it.  How do I do this in 



More information about the Python-list mailing list