What's the best way in Python
to make code independent from where it is located?
In a project of mine I have a lot of code (in different files) which all need to access the same objects defined and created somewhere else.
In a perfect world:
somewhere.py
from registry import register
...
register(Cat(), "cat")
...
somewhere_else.py
from magic import cat
...
cat.pet()
...
However this would most likely involve overriding the import system, so I'm also happy with any implementation that sort of mimics this system, ex. magic.get('cat')
instead of from magic import cat
.
Any ideas?