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


Groups > comp.lang.python > #96247

Question about import

Path csiph.com!eternal-september.org!feeder.eternal-september.org!border1.nntp.ams1.giganews.com!nntp.giganews.com!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail
Return-Path <python-python-list@m.gmane.org>
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; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.10; 'def': 0.13; 'applies': 0.15; 'packages.': 0.15; 'bump': 0.16; 'comprises': 0.16; 'missing?': 0.16; 'module?': 0.16; 'modules,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:import': 0.16; 'surprising': 0.16; 'circular': 0.18; 'project,': 0.18; 'split': 0.23; 'import': 0.24; 'example': 0.26; 'header:X-Complaints-To:1': 0.26; 'appreciated.': 0.27; 'wonder': 0.27; 'question': 0.27; 'package.': 0.27; "skip:' 10": 0.28; 'fine': 0.28; 'if,': 0.29; 'occasionally': 0.29; 'solution,': 0.29; 'comments': 0.30; 'that.': 0.30; 'another': 0.32; 'noticed': 0.32; 'getting': 0.33; 'know.': 0.34; 'that,': 0.34; 'something': 0.35; 'but': 0.36; 'project': 0.36; 'modules': 0.36; 'to:addr:python-list': 0.36; 'say': 0.37; 'received:org': 0.37; 'one,': 0.37; 'thought': 0.37; 'to:addr:python.org': 0.40; 'still': 0.40; 'provide': 0.61; 'different': 0.63; 'within': 0.64; 'here': 0.66; 'dangerous': 0.70; 'frank': 0.72; 'aaa': 0.84; 'odd,': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From "Frank Millman" <frank@chagford.com>
Subject Question about import
Date Thu, 10 Sep 2015 09:12:29 +0200
Mime-Version 1.0
Content-Type text/plain; format=flowed; charset="iso-8859-1"; reply-type=original
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host 197.89.14.191
X-MSMail-Priority Normal
Importance Normal
X-Newsreader Microsoft Windows Live Mail 15.4.3502.922
X-MimeOLE Produced By Microsoft MimeOLE V15.4.3502.922
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.311.1441869188.8327.python-list@python.org> (permalink)
Lines 64
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1441869188 news.xs4all.nl 23726 [2001:888:2000:d::a6]:44090
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:96247

Show key headers only | View raw


Hi all

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.

I have just noticed something odd, and I wondered if it might provide a 
solution, or if it is a dangerous sidetrack. Here is a simple example -

/test
| start.py
  /a
  | aa.py
  /b
  | bb.py

start.py
    import a.aa
    import b.bb
    a.aa.aaa()
    b.bb.bbb()

aa.py
    import b
    def aaa():
        print('in aaa')
        b.bb.bbbb()
    def aaaa():
            print('in aaaa')

bb.py
    import a
    def bbb():
        print('in bbb')
        a.aa.aaaa()
    def bbbb():
        print('in bbbb')

c:\test>start.py
in aaa
in bbbb
in bbb
in aaaa

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'.

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?

Another question - I thought that, because aa.py and bb.py are in different 
sub-directories, I would have to set them up as packages by adding 
'__init__.py' to each one, but it works fine without that. What am I 
missing?

I am using python 3.4.

Any comments appreciated.

Frank Millman

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


Thread

Question about import "Frank Millman" <frank@chagford.com> - 2015-09-10 09:12 +0200

csiph-web