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


Groups > comp.lang.python > #13276

Re: ImportError: cannot import name dns

References <CAAuurf+q=Z8sfD1GaNCKNAzFz=VzLVq2gUtHgjcsGLn7sFNXKg@mail.gmail.com> <0604E20B5F6F2F4784C9C8C71C5DD4DD2F16BB4719@EMARC112VS01.exchad.jpmchase.net>
Date 2011-09-14 09:22 -0700
Subject Re: ImportError: cannot import name dns
From Jack Bates <jack.bates@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.1121.1316017681.27778.python-list@python.org> (permalink)

Show all headers | View raw


> 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?

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


Thread

Re: ImportError: cannot import name dns Jack Bates <jack.bates@gmail.com> - 2011-09-14 09:22 -0700

csiph-web