Is it possible to import a module of the same package with an alias using relative import?
Say I have the following package structure:
lib/
foobar/
__init__.py
foo.py
bar.py
And in foo.py, I'd like to use something from bar.py, but I'd like to use it as "bar.my_function", so instead of from .bar import my_function, I've tried import .bar as bar and import .bar, both of which don't work (invalid syntax exception). I've tried both pythhon2.7 and python3.4 (the latter being my target version).
However, what DOES work, and what I'm using now, is import foobar.bar as bar, i.e. absolute import instead of relative. It's an OK solution, given I don't expect the package name to change (and even if it does, there's not much to change in the code), but it would be nice if I could accomplish this using relative import!
Summary:
#import .bar as bar # why not?!?
#import .bar # shot in the dark
import foobar.bar as bar # current solution