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: 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: References: Date: Sun, 16 Nov 2014 20:20:56 +1100 Subject: Re: caught in the import web again From: Chris Angelico Cc: "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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 On Sun, Nov 16, 2014 at 7:53 PM, Charles T. Smith 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