I have a package called sound with a directory structure like so:
sound/ |-- __init__.py |-- interpreter.py |-- blast.py Before I had the package, interpreter.py would import blast.py with the command import blast. Now with the package I have to say import sound.blast as blast.
While I don't mind this, I'd like to be able to both import the sound package outside of it's directory with that statement, but also to run interpreter.py directly. But if I run interpreter.py directly, I get an import error saying that sound doesn't exist.
My current solution is something like this:
try: import sound.blast except ImportError: import blast But this feels ugly. Is there a better solution for this?