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: 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: References: Date: Sun, 26 Apr 2015 09:53:07 +1000 Subject: Re: Library import succeeds with nose, fails elsewhere From: Chris Angelico Cc: "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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 On Sun, Apr 26, 2015 at 9:36 AM, 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 impor= ting 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) differen= t ways I could handle it. My intent was that now I can refer to awesome.uti= l.helper regardless of where I am (outside the package, within different di= rectories, etc). My guess is that doing things like importing 'helper' dire= ctly 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