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

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'package,': 0.03; 'explicitly': 0.05; 'importing': 0.05; 'referring': 0.07; 'etc).': 0.09; 'things,': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'background.': 0.14; '"from': 0.16; 'awesome.': 0.16; 'does,': 0.16; 'fine.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'subdirectory': 0.16; 'subject:fails': 0.16; 'subject:import': 0.16; 'top-level': 0.16; 'wrote:': 0.18; 'import': 0.22; 'saying': 0.22; 'cc:addr:python.org': 0.22; 'certainly': 0.24; 'package.': 0.24; 'regardless': 0.24; 'file.': 0.24; 'cc:2**0': 0.24; 'header:In- Reply-To:1': 0.27; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; 'file': 0.32; 'guess': 0.33; 'could': 0.34; 'subject:with': 0.35; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'doing': 0.36; "didn't": 0.36; 'being': 0.38; 'awesome': 0.38; 'handle': 0.38; 'that,': 0.38; '(from': 0.39; 'refer': 0.63; 'more': 0.64; 'different': 0.65; 'within': 0.65; '26,': 0.68; '2015': 0.84; 'directories,': 0.84; 'to:none': 0.92; 'directly.': 0.95
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type:content-transfer-encoding; bh=6rOCILXvghGved/Q4Bzo2rdDHsYYklKTq/xZ+3G8M+I=; b=iuuFsNf4uaxojfkPoKOd8JKPPvW9KIXIVwrG6aoSv4yI6z/+dGp1MxJh4HAlNQwB4m 1i81/ahemFvHPEHzvjEeb2vh5fDhI5ZccOePf3igTULh9NPjAETKW+jee7dheUqciTqZ hkWHQoVUXo+mnoB/h3cIOgqDlj5FqHkXxig4vL3j5uIkMzjo+Z6S+toBe7qxdSAM1xGS /fiYYo7xPXesxhKRW9ya5UbKjpmSRMG5hzbhzQ7BMRCOdyGpRRG3E8F5/PNh5LqqJZLZ WencSEfvdQ5L6Zc6tjZ3fC5MtepJVH6E37RprhmxcrO2QSZxzFfGF3R4oRvtY7XBY2Y9 j/dQ==
MIME-Version 1.0
X-Received by 10.50.43.196 with SMTP id y4mr5434926igl.14.1430005987874; Sat, 25 Apr 2015 16:53:07 -0700 (PDT)
In-Reply-To <a890820d-e5cf-438d-ae54-4442a6eb4e70@googlegroups.com>
References <cd680312-ab2e-4303-aa20-7aa521a2f5fe@googlegroups.com> <mailman.19.1430001979.3680.python-list@python.org> <a890820d-e5cf-438d-ae54-4442a6eb4e70@googlegroups.com>
Date Sun, 26 Apr 2015 09:53:07 +1000
Subject Re: Library import succeeds with nose, fails elsewhere
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.20.1430005996.3680.python-list@python.org> (permalink)
Lines 31
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1430005996 news.xs4all.nl 2857 [2001:888:2000:d::a6]:38007
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:89406

Show key headers only | 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