Path: csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'subject:Question': 0.05; 'modules.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'applies': 0.15; 'importing': 0.15; 'packages.': 0.15; '"."': 0.16; '".",': 0.16; 'bump': 0.16; 'comprises': 0.16; 'cyclic': 0.16; 'ideally,': 0.16; 'module?': 0.16; 'modules,': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'refactoring': 0.16; 'subject:import': 0.16; 'surprising': 0.16; 'circular': 0.18; 'project,': 0.18; 'split': 0.23; 'import': 0.24; 'header:User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'order.': 0.27; 'wonder': 0.27; 'package.': 0.27; 'projects,': 0.27; 'if,': 0.29; 'occasionally': 0.29; 'thus,': 0.29; 'getting': 0.33; 'know.': 0.34; 'that,': 0.34; 'could': 0.35; 'problem.': 0.35; 'but': 0.36; 'should': 0.36; 'project': 0.36; 'modules': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'say': 0.37; 'received:org': 0.37; 'charset:us-ascii': 0.37; 'to:addr:python.org': 0.40; 'still': 0.40; 'received:de': 0.40; 'your': 0.60; 'side': 0.62; 'different': 0.63; 'within': 0.64; 'between': 0.65; 'respect': 0.65; 'accessed': 0.66; 'reuse': 0.66; 'received:217': 0.66; 'grow': 0.75; '"".': 0.84; 'vulnerable': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: dieter Subject: Re: Question about import Date: Fri, 11 Sep 2015 08:29:12 +0200 References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Gmane-NNTP-Posting-Host: pd9e09824.dip0.t-ipconnect.de User-Agent: Gnus/5.1008 (Gnus v5.10.8) XEmacs/21.4.22 (linux) Cancel-Lock: sha1:VeozmSAxkeJjd3+rR0Q2tKL/+sY= 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: 33 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1441952977 news.xs4all.nl 23859 [2001:888:2000:d::a6]:40754 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:96324 "Frank Millman" writes: >... > My project comprises a number of modules, split into packages. Modules > frequently need to access the contents of other modules, in the same > or in a different package. I am getting better at it, but I still > occasionally bump my head against circular imports, and have to fiddle > around until it settles down again. Not ideal, I know. Ideally, you have only oneway dependencies between modules. In most cases, cyclic dependencies can be removed by refactoring - yielding a better architecture. > ... > The surprising thing is that, within aa.py, I just have to say 'import > b', and I can access 'b.bb.bbbb', and the same applies to 'bb.py'. As a side effect of importing "." "" is bound in "". Thus, after the first import of ".", "" can be accessed via "" after only importing "". > That makes me wonder if, in my project, I can import all modules > inside 'start.py', and then just use 'import package_name' inside each > module? You could - but you should not as this make you vulnerable with respect to the import order. In a small project, this is likely no problem. However, when your projects grow and reuse components intially developped for other projects, this may become unfeasable.