Library import succeeds with nose, fails elsewhere
alister
alister.nospam.ware at ntlworld.com
Sat Apr 25 15:38:55 EDT 2015
On Sat, 25 Apr 2015 10:48:23 -0700, richmolj wrote:
> Apologies, I'm a rubyist and this is a beginner question but I'm not
> finding a great answer with lots of googling. I am writing a library,
> organized something like this:
>
> awesome_lib/awesome.py awesome_lib/util/__init__.py
> awesome_lib/util/helper.py
>
> In the top of awesome.py:
>
> foo = 'bar'
> import helper
>
> In the top of helper.py:
>
> import awesome print awesome.foo
>
> IRL, I'm doing this for things like referring to the main logger from
> within the utility method.
>
> This works great when running tests through nose. In a test file I
> 'import awesome', refer to awesome.helper and everything is fine.
>
> If I try to put this library into a project, however, the import fails:
>
> ~/foo.py ~/awesome_lib
>
> 'python foo.py' (only code is 'from awesome_lib import awesome')
> ImportError: No module named awesome
>
> The error occurs when importing the helper and it tries to 'import
> awesome' and fails.
>
> I'm sure I am doing something stupid, can someone point me in the right
> direction?
you seem to have a recursive import going on
Awesome imports helper, helper imports awesome this is always a cauise of
problems & is usually a code smell.
if these two modules are that heavily interlinked then you probably want
all the code in one single module.
--
All syllogisms have three parts, therefore this is not a syllogism.
More information about the Python-list
mailing list