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


Groups > comp.lang.python > #80868

Re: caught in the import web again

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!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.008
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; '16,': 0.03; 'broken': 0.04; 'suddenly': 0.07; 'structure,': 0.09; 'cc:addr:python-list': 0.11; 'def': 0.12; 'charles': 0.16; 'file1': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'imports': 0.16; 'subject:caught': 0.16; 'subject:import': 0.16; 'wrote:': 0.18; 'properly': 0.19; 'code,': 0.22; 'import': 0.22; 'cc:addr:python.org': 0.22; 'necessary.': 0.24; 'oriented': 0.24; 'cc:2**0': 0.24; 'this:': 0.26; 'pass': 0.26; 'header:In-Reply- To:1': 0.27; 'strongly': 0.30; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'another.': 0.31; 'fine,': 0.31; 'class': 0.32; "we're": 0.32; 'another': 0.32; 'subject:the': 0.34; 'knowledge': 0.35; 'classes': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'configured': 0.38; 'nov': 0.38; 'pm,': 0.38; 'little': 0.38; 'first': 0.61; 'such': 0.63; 'talking': 0.65; 'smith': 0.68; 'other.': 0.75; 'bar:': 0.84; 'complex,': 0.84; 'to:none': 0.92; 'remember,': 0.93
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; bh=FqC5dUgTeu8T2yWbUTtpEivyJcc98fRNnVHlJgo99yE=; b=dZbkh44xjIl76gVtfZiql+fQUa9hmthpYwzVS+OPJMNXArv618a2O+OdDWzq9sX0c7 1jN0BUHu5rKn1n0s/Y18lxKSRdPEhNG4E9e69emEC2Rfb7v+NI6GjBwp8aoe8Kjn5BE6 U/mkVcxoogFG5DkKfKFer41jvWOK7fZY37dN4D3/ly9t/MH0oi75QJQhO/MDLKDmCes+ y6hWgP4ZfwhA9uUR3rvsQIwvOMWSBhvr19tBvsaxHnyQcK6jJAQlWCm0pxoQI0qPdqc9 frpTXmBW/XmiEVnL8EQNjQpXcS7Reu7IKk4LIWEsK6Kxoo53KvKmivUGI6vqP4foOV7E 5dwA==
MIME-Version 1.0
X-Received by 10.50.110.4 with SMTP id hw4mr18213667igb.14.1416129656740; Sun, 16 Nov 2014 01:20:56 -0800 (PST)
In-Reply-To <m49omd$924$1@dont-email.me>
References <m48lfh$n88$1@dont-email.me> <mailman.15871.1416122062.18130.python-list@python.org> <m49omd$924$1@dont-email.me>
Date Sun, 16 Nov 2014 20:20:56 +1100
Subject Re: caught in the import web again
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
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.15878.1416129659.18130.python-list@python.org> (permalink)
Lines 39
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1416129659 news.xs4all.nl 2871 [2001:888:2000:d::a6]:45369
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:80868

Show key headers only | View raw


On Sun, Nov 16, 2014 at 7:53 PM, Charles T. Smith
<cts.private.yahoo@gmail.com> wrote:
> Yes, we're talking about recursive imports here.  It's a complex, object-
> oriented system with big classes and little classes that are strongly
> interrelated.  I can get the imports configured properly so everything
> works but if I make a little change to the code, then suddenly all my
> imports are broken and I must painstakingly go through the whole
> structure, reorganizing them.

So reorganize *once*, such that there are no recursive imports.
Reorganize your code so things don't actually import one another.
Remember, you can pass an instance of some class to an instance of
another class that has no knowledge of the first class - like this:

# file1.py

class Foo:
    def some_method(self, some_obj):
        some_obj.some_other_method()

# file2.py

class Bar:
    def some_other_method(self):
        return 42

# main.py

import file1, file2

f=file1.Foo()
b=file2.Bar()
f.some_method(b)


This works just fine, and neither file1 nor file2 needs to import the
other. Recursive imports are almost never necessary.

ChrisA

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


Thread

caught in the import web again "Charles T. Smith" <cts.private.yahoo@gmail.com> - 2014-11-15 22:52 +0000
  Re: caught in the import web again Ben Finney <ben+python@benfinney.id.au> - 2014-11-16 10:43 +1100
  Re: caught in the import web again Denis McMahon <denismfmcmahon@gmail.com> - 2014-11-16 01:11 +0000
  Re: caught in the import web again dieter <dieter@handshake.de> - 2014-11-16 08:14 +0100
    Re: caught in the import web again "Charles T. Smith" <cts.private.yahoo@gmail.com> - 2014-11-16 08:53 +0000
      Re: caught in the import web again Chris Angelico <rosuav@gmail.com> - 2014-11-16 20:20 +1100
      Re: caught in the import web again dieter <dieter@handshake.de> - 2014-11-17 08:08 +0100
        Re: caught in the import web again "Charles T. Smith" <cts.private.yahoo@gmail.com> - 2014-11-17 20:07 +0000
          Re: caught in the import web again Dave Angel <davea@davea.name> - 2014-11-17 17:17 -0500
          Re: caught in the import web again Ian Kelly <ian.g.kelly@gmail.com> - 2014-11-17 15:52 -0700
          Re: caught in the import web again Dave Angel <davea@davea.name> - 2014-11-17 20:20 -0500
          Re: caught in the import web again Ian Kelly <ian.g.kelly@gmail.com> - 2014-11-18 08:28 -0700
          Re: caught in the import web again Dave Angel <davea@davea.name> - 2014-11-18 14:09 -0500
          Re: caught in the import web again Chris Angelico <rosuav@gmail.com> - 2014-11-19 07:18 +1100
          Re: caught in the import web again Dave Angel <davea@davea.name> - 2014-11-18 17:58 -0500
      Re: caught in the import web again Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-11-18 09:45 +1100
        Re: caught in the import web again Rick Johnson <rantingrickjohnson@gmail.com> - 2014-11-17 18:17 -0800
          Re: caught in the import web again Chris Angelico <rosuav@gmail.com> - 2014-11-18 13:25 +1100
          Re: caught in the import web again Steven D'Aprano <steve@pearwood.info> - 2014-11-18 07:13 +0000
        Re: caught in the import web again Michael Torrie <torriem@gmail.com> - 2014-11-18 00:00 -0700
          Re: caught in the import web again "Charles T. Smith" <cts.private.yahoo@gmail.com> - 2014-11-18 09:13 +0000

csiph-web