Skip to content
Advertisement

How to use a python module on inherited class

I have a base class A in base.py:

JavaScript

Then in new.py I created a new class B which inherits A and override test method:

JavaScript

The problem is that the module1 is no longer available in new.py. Is there any options that I do not need to import module1 again in new.py?

Advertisement

Answer

One not recommended way to achieve what you want is to use __builtins__. Add the following line to base.py.

JavaScript

Then module1 is no longer undefined from new.py. It is definitely defined in __builtins__.

Again, it is not recommended, however, good to understand how Python works. You would better import module1 from new.py as well.

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement