Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeder.news-service.com!news2.euro.net!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'circular': 0.03; 'attempting': 0.04; 'symbols': 0.07; 'python': 0.08; 'dependency': 0.09; 'foo': 0.09; 'namespace': 0.09; 'raised.': 0.09; 'received:209.85.160.174': 0.09; 'received:mail- gy0-f174.google.com': 0.09; '"from': 0.16; '(initially': 0.16; 'importerror': 0.16; 'subject:import': 0.16; 'url:effbot': 0.16; 'url:zone': 0.16; 'cc:addr:python-list': 0.16; 'endless': 0.18; 'to:2**1': 0.20; 'cc:2**0': 0.22; 'header:In-Reply-To:1': 0.22; 'module,': 0.23; 'expect': 0.25; 'import': 0.28; 'message- id:@mail.gmail.com': 0.29; 'cc:addr:python.org': 0.30; 'module': 0.30; "isn't": 0.33; 'instead': 0.33; 'done': 0.34; 'dns': 0.34; 'like:': 0.34; 'received:209.85.160': 0.35; 'url:python': 0.36; 'executing': 0.37; 'something': 0.37; '(not': 0.38; 'received:google.com': 0.38; 'url:org': 0.38; 'received:209.85': 0.38; 'subject:: ': 0.39; 'url:docs': 0.39; 'empty': 0.39; "i'd": 0.40; 'according': 0.62; 'subject:name': 0.67; 'url:htm': 0.72; 'cycle;': 0.84; 'url:reference': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=s7CNMJ9sGS1B1/p//nBkYd8UttwlEZpxUs+Ew3Dkj/c=; b=GqYbaH+h6Al2ahgXOs7wUUYJals2l7dlPDhAAsMprT0Ahh/t+BxZw3GTPjitBWZBQc 0OaVVOhsbkyLLRAmHMJHbcIofrYXBm1VmzczeALFQzDh2iB0UPwOdzFjPNqp8Uckht0Q fylMmaz3KTmEBw0lLAAMzRE1AvcDyZ8mj3jH0= MIME-Version: 1.0 In-Reply-To: <0604E20B5F6F2F4784C9C8C71C5DD4DD2F16BB4719@EMARC112VS01.exchad.jpmchase.net> References: <0604E20B5F6F2F4784C9C8C71C5DD4DD2F16BB4719@EMARC112VS01.exchad.jpmchase.net> Date: Wed, 14 Sep 2011 09:22:29 -0700 Subject: Re: ImportError: cannot import name dns From: Jack Bates To: "Prasad, Ramit" Content-Type: text/plain; charset=ISO-8859-1 Cc: "python-list@python.org" X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 28 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1316017685 news.xs4all.nl 2441 [2001:888:2000:d::a6]:40950 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:13276 > It is a circular dependency. Dns will try to import udp which will in turn import dns (again) in an endless cycle; instead an ImportError is raised. > > Circular dependency is a Bad Thing. According to this documentation: http://docs.python.org/reference/simple_stmts.html#grammar-token-import_stmt http://effbot.org/zone/import-confusion.htm - I thought Python would do something like: 1. check for "dns" in sys.modules (initially not found) 2. create new empty module, add it to sys.modules as "dns" 3. execute dns.py in new module namespace (executes "from foo import udp") 4. check for "udp" in sys.modules (not found) 5. create new empty module, add it to sys.modules as "udp" 6. execute udp.py in new module namespace (executes "from foo import dns") 7. check for "dns" in sys.modules (found!) 8. done executing udp.py 9. done executing dns.py So I'd expect attempting to access symbols from "dns" while executing udp.py to fail, because dns.py isn't done executing at this point. However I don't attempt to access any symbols from "dns" - so I don't expect this ImportError What is my mistake?