I'm having some trouble with class inheritance in Python 3.1x that I am hoping to get some help with. I have a class called ClassA and I am trying to create another class called ClassB that inherits from ClassA. Here is the code I've written:
from myfile import ClassA
class ClassB(ClassA):
def __init__(self):
super(ClassB, self).__init__()
When I try to create an instance of ClassB I get this error:
>>> x = ClassB()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'ClassB' is not defined
Which is my problem?
ROMANIA_engineer
57.1k30 gold badges211 silver badges207 bronze badges
asked Oct 2, 2011 at 22:07
drbunsen
10.8k22 gold badges71 silver badges94 bronze badges
1 Answer 1
The problem is that you're not referring to what you've imported.
>>> import SomeModule
>>> x = SomeModule.ClassB()
answered Oct 2, 2011 at 22:12
Ignacio Vazquez-Abrams
804k160 gold badges1.4k silver badges1.4k bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-py