Hi,
Update: This is, as I was told, no principle Python related problem, but seems to be more specific. See below for more explanations to my problem.
I have a custom exception (let's call it CustomException), that lives in a file named exceptions.py. Now imagine, that I can import this file via two paths:
import application.exceptions
or
import some.application.exceptions
with the same result. Furthermore I have no control over which way the module is imported in other modules.
Now to show my problem: Assume that the function do_something comes from another module that imports exceptions.py in a way I don't know. If I do this:
import application.exceptions
try:
do_something ()
except application.exceptions.CustomException:
catch_me ()
it might work or not, depending on how the sub-module imported exceptions.py (which I do not know).
Question: Is there a way to circumvent this problem, i.e., a name for the exception that will always be understood regardless of inclusion path? If not, what would be best practices to avoid these name clashes?
Cheers,
Update
It is a Django app. some would be the name of the Django 'project', application the name of one Django app. My code with the try..except clause sits in another app, frontend, and lives there as a view in a file some/frontend/views.py.
The PYTHONPATH is clean, that is, from my project only /path/to/project is in the path. In the frontend/views.py I import the exceptions.py via import application.exceptions, which seems to work. (Now, in retrospective, I don't know exactly, why it works...)
The exception is raised in the exceptions.py file itself.