Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4a.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.023 X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; 'level,': 0.07; 'postpone': 0.07; 'references.': 0.09; 'python': 0.11; 'wrote': 0.14; 'function?': 0.16; 'imports': 0.16; 'modules.': 0.16; 'smith"': 0.16; 'subject:caught': 0.16; 'subject:import': 0.16; 'wrote:': 0.18; 'module': 0.19; 'basically': 0.19; 'finished': 0.19; 'import': 0.22; 'putting': 0.22; 'module,': 0.24; 'mon,': 0.24; 'gets': 0.27; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'evaluation': 0.30; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'guess': 0.33; 'subject:the': 0.34; 'problem': 0.35; 'received:google.com': 0.35; 'there': 0.35; "i'll": 0.36; 'responsible': 0.36; 'similar': 0.36; 'depends': 0.38; 'nov': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'called': 0.40; 'dave': 0.60; 'tips': 0.61; 'such': 0.63; 'forward': 0.65; '(that': 0.65; 'hoping': 0.75; 'delaying': 0.84; 'angel': 0.91; 'good,': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=S3oTR4EcSqLG4wZWVf8fsGoIr2iAprufdFJwHSomqGY=; b=m2T8KhXm881G6CeFM0oheH7aOghwDQXB9hnN957DRx3Y+T8eyQSM75N4gGQBn7Hl5t yeN4xN70c76HCvPpWs0bq+WyNmf/zffOC4NGlDPjodmgBneOthqMWdV2RNU+WQ1nUOIb jIPDpOfkis2QhUwyPMTp14Wm3/SRY7B3cp9wn1a3kvWnfSBfD/HOOA6NCLVDGuy1B+Pt SGMNarNyx42Q6O42DAmqMd6BZJbinFbAd/c22T2Hz9XTSi9UqEHQYRcxP85J9OBxHgDF TfJXDHcctQhruCKUF+R3v+B5AiLPZYFxl41yzuFgIsgTIP+id5/pxqlLpI4Q+/tkAvum Sdng== X-Received: by 10.67.14.129 with SMTP id fg1mr12895005pad.114.1416264793067; Mon, 17 Nov 2014 14:53:13 -0800 (PST) MIME-Version: 1.0 In-Reply-To: References: From: Ian Kelly Date: Mon, 17 Nov 2014 15:52:32 -0700 Subject: Re: caught in the import web again To: Python 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: 20 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1416264801 news.xs4all.nl 2849 [2001:888:2000:d::a6]:38786 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:80986 On Mon, Nov 17, 2014 at 3:17 PM, Dave Angel wrote: > "Charles T. Smith" Wrote in message: > >> Well, I guess that's the definitive answer... the tips for delaying >> import are good, I'll try to leverage them. >> >> I was hoping there would be a way to have python postpone evaluation >> similar to C's forward references. >> > > In a module that might get tangled in a cycle, avoid global code > that depends on other modules. Instead of putting such > initialization at top level, put inside a function that gets > called after all suspect imports are completed. (That function > has global keywords ). If the problem is that one of those modules would import the current module, then "after all suspect imports are completed" basically means after the current module has finished importing. So what would be responsible for calling such a function?