how to access custom exception handler from python module? -
these files:
mymodule/__init__.py import sys class mymodule: handle_exceptions = handle_exceptions def __init__(self): sys.excepthook = handle_exceptions #mymodule/handle_exceptions.py def handle_exceptions(ex_cls, ex, tb): #not important here pass #my_script.py import sys import mymodule sys.excepthook = mymodule.handle_exceptions
the contents of 'handle_exceptions' not important here because can't access @ all.
traceback (most recent call last): file "my_script.py", line 2, in <module> import mymodule file "d:\python34\mymodule\__init__.py", line 3, in <module> class mymodule: file "d:\python34\mymodule\__init__.py", line 4, in mymodule handle_exceptions = handle_exceptions nameerror: name 'handle_exceptions' not defined
try this
mymodule/__init__.py import sys class mymodule: def __init__(self): sys.excepthook = handle_exceptions self.handle_exceptions = handle_exceptions #mymodule/handle_exceptions.py def handle_exceptions(ex_cls, ex, tb): #not important here pass import sys mymodule import handle_exceptions sys.excepthook = handle_exceptions
Comments
Post a Comment