I have a module that imports a module, but in some cases the imported module may not exist. After importing a module, there is a class that inherits from the class the imported module. If I were to catch an exception ImportErrorif the module does not exist, how can I stop Python from parsing the rest of the module? I am open to other solutions if this is not possible.
Here is a basic example (selfaware.py):
try:
from skynet import SkyNet
except ImportError:
class SelfAwareSkyNet():
pass
exit_module_parsing_here()
class SelfAwareSkyNet(SkyNet):
pass
The only thing I can do is: