i have a 2.6 python script and library in the following directory structure:
+ bin
\- foo.py
+ lib
\+ foo
\- bar.py
i would like users to run bin/foo.py
to instantiate the classes within lib/foo.py
. to achieve this, in my bin/foo.py
script i have the following code:
from __future__ import absolute_import
import foo
klass = foo.bar.Klass()
however, this results in:
AttributeError: 'module' object has no attribute 'bar'
ie it thinks that foo
is itself rather than the library foo
- renaming bin/foo.py
to bin/foo-script.py
works as expected.
is there a way i can keep the bin/foo.py
script and import lib/foo.py
?
import foo as bar
? – Steve Peak Jan 24 at 19:48