tags:

views:

27

answers:

2

Hi Guys!

I'd like to stop the loading of a module if some modules dependencies arent on machine, how can i do that?

try:
    import lxml
except:
    print "This module requires lxml"
    # WHAT SHOULD I PUT HERE TO STOP MODULE LOADING?

class foo:
    pass
+1  A: 

Raise the exception, or raise a new one:

try:
    import lxml
except:
    raise SomeError('This module requires lxml')

If you want to stop the interpreter entirely, use exit() to terminate the program.

Yuval A
A: 

To stop the whole python interpreter you can use sys.exit()

Mark