ImportError: cannot import name dns

Prasad, Ramit ramit.prasad at jpmorgan.com
Tue Sep 13 19:09:50 EDT 2011


-----Original Message-----
From: python-list-bounces+ramit.prasad=jpmorgan.com at python.org [mailto:python-list-bounces+ramit.prasad=jpmorgan.com at python.org] On Behalf Of Jack Bates
Sent: Tuesday, September 13, 2011 5:28 PM
To: python-list at python.org
Subject: ImportError: cannot import name dns

Why is the following ImportError raised?

$ ./test
Traceback (most recent call last):
  File "./test", line 3, in <module>
    from foo import dns
  File "/home/jablko/foo/dns.py", line 1, in <module>
    from foo import udp
  File "/home/jablko/foo/udp.py", line 1, in <module>
    from foo import dns
ImportError: cannot import name dns
$

I reproduce this error with the following four files and five lines:

== foo/dns.py ==
from foo import udp

== foo/udp.py ==
from foo import dns

== foo/__init__.py ==
(empty)

== test ==
#!/usr/bin/env python

from foo import dns


===========================================================================
 
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.

Ramit


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423


This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  



More information about the Python-list mailing list