Path: csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-1.proxad.net!217.188.199.168.MISMATCH!takemy.news.telefonica.de!telefonica.de!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'explicitly': 0.05; 'explicit': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:modules': 0.09; 'python': 0.11; '*only*': 0.16; 'absolute,': 0.16; 'finney': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'have:': 0.19; 'import': 0.22; '(in': 0.22; 'header:User-Agent:1': 0.23; 'fine': 0.24; 'skip:" 30': 0.26; 'subject:/': 0.26; 'header:X-Complaints-To:1': 0.27; 'tried': 0.27; 'absolute': 0.30; 'relative': 0.30; 'asked': 0.31; 'went': 0.31; 'wright': 0.31; 'writes:': 0.31; 'file': 0.32; "i'd": 0.34; 'subject:from': 0.34; "can't": 0.35; 'common': 0.35; 'done': 0.36; 'doing': 0.36; 'subject:?': 0.36; 'should': 0.36; 'ben': 0.38; 'to:addr:python-list': 0.38; 'skip:. 10': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'default': 0.69; 'borrow': 0.84; 'victor': 0.84; 'package:': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Ben Finney Subject: Re: Organising packages/modules - importing functions from a common.py in a separate directory? Date: Tue, 29 Oct 2013 12:01:03 +1100 References: <9283f879-b872-43af-a072-0dff088421d8@googlegroups.com> <7497d2bc-a42c-498b-9167-d86165401db8@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: rasputin.madmonks.org X-Public-Key-ID: 0xAC128405 X-Public-Key-Fingerprint: 517C F14B B2F3 98B0 CB35 4855 B8B2 4C06 AC12 8405 X-Public-Key-URL: http://www.benfinney.id.au/contact/bfinney-gpg.asc X-Post-From: Ben Finney User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux) Cancel-Lock: sha1:iATwUAZhIm8m4lJ/Y7LppKWXuoE= X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 34 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1383008475 news.xs4all.nl 15878 [2001:888:2000:d::a6]:54155 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:57866 Victor Hooi writes: > Ok, so I should be using absolute imports, not relative imports. I'd say it is fine to use relative imports, so long as they are explicit. (In Python 3, the default for an import is to be absolute, and the *only* way to do a relative import is to make it explicitly relative. So you may as well start doing so now.) > Hmm, I just tried to use absolute imports, and it can't seem to locate > the modules: > > In the file "foo_loading/em_load/sync_em.py", I have: > > from common.common_bex import setup_foo_logging So I'd recommend this be done with an explicit relative import: from .common.common_bex import setup_foo_logging or, better, import a module: from .common import common_bex or a whole package: from . import common -- \ “I went over to the neighbor's and asked to borrow a cup of | `\ salt. ‘What are you making?’ ‘A salt lick.’” —Steven Wright | _o__) | Ben Finney