Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #89406

Re: Library import succeeds with nose, fails elsewhere

References <cd680312-ab2e-4303-aa20-7aa521a2f5fe@googlegroups.com> <mailman.19.1430001979.3680.python-list@python.org> <a890820d-e5cf-438d-ae54-4442a6eb4e70@googlegroups.com>
Date 2015-04-26 09:53 +1000
Subject Re: Library import succeeds with nose, fails elsewhere
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.20.1430005996.3680.python-list@python.org> (permalink)

Show all headers | View raw


On Sun, Apr 26, 2015 at 9:36 AM,  <richmolj@gmail.com> wrote:
> The solution ended up being editing the top-level __init__.py:
>
> import awesome
>
> and then *when in a subdirectory*:
>
> import awesome_lib as awesome
>
> and *when in a different top-level file*:
>
> import awesome.
>
> IOW (from what I can tell) I made importing the package the same as importing this one file. When in a subdirectory import via the package, when in a sibling file import the file directly.
>
> This certainly feels odd, and I did find some (likely preferred) different ways I could handle it. My intent was that now I can refer to awesome.util.helper regardless of where I am (outside the package, within different directories, etc). My guess is that doing things like importing 'helper' directly and referring to it as 'helper' (no awesome.util prefix) is the python way of doing things, just didn't ring true with my background.
>

Give "from . import helper" a try; you may find that it works just as
well as "import helper" does, but more explicitly saying that you want
it from the current package. Other than that, I think you have
something that'll work fine.

ChrisA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Library import succeeds with nose, fails elsewhere richmolj@gmail.com - 2015-04-25 10:48 -0700
  Re: Library import succeeds with nose, fails elsewhere alister <alister.nospam.ware@ntlworld.com> - 2015-04-25 19:38 +0000
  Re: Library import succeeds with nose, fails elsewhere alister <alister.nospam.ware@ntlworld.com> - 2015-04-25 19:38 +0000
  Re: Library import succeeds with nose, fails elsewhere Chris Angelico <rosuav@gmail.com> - 2015-04-26 08:46 +1000
    Re: Library import succeeds with nose, fails elsewhere richmolj@gmail.com - 2015-04-25 16:36 -0700
      Re: Library import succeeds with nose, fails elsewhere Chris Angelico <rosuav@gmail.com> - 2015-04-26 09:53 +1000
        Re: Library import succeeds with nose, fails elsewhere richmolj@gmail.com - 2015-04-26 06:40 -0700

csiph-web