[Tutor] Class Inheritance -> NameError

Tim Johnson tim at johnsons-web.com
Thu Dec 1 03:46:05 CET 2005


The following code snippet is meant to test inheritance:
class test:
    def __init__(self,v):
        self.__val = v
    def val(self):
        print self.__val
class sub(test):
    def __init__(self):
        val()
The following console session has an error:
>>> T = mylib.test('hello')
>>> s = mylib.sub()
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "mylib.py", line 1612, in __init__
    val()
NameError: global name 'val' is not defined

## what do I need to do to make the 'test method visible
## class 'sub?
thanks
tim

-- 
Tim Johnson <tim at johnsons-web.com>
      http://www.alaska-internet-solutions.com


More information about the Tutor mailing list