By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,100 Members | 2,846 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,100 IT Pros & Developers. It's quick & easy.

circular import problem

P: n/a
An example in the book I didn't understood well
two modules files recursively import/from each other

in recur1.py,we have:

x=1
import recur2
y=1
in recur2.py, we have

from recur1 import x
from recur1 import y
If we run interactively at python command line,
import recur1

it has errors like this:
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "recur1.py", line 2, in ?
import recur2
File "recur2.py", line 2, in ?
from recur1 import y
ImportError: cannot import name y

I understood this because recur1 is not finished when recur2 is trying
to import y.

However, if you run interactive for recur2.py interactively, it is
fine.
when you run as script from command line, recur1.py is fine. but when
you
python recur2.py at commmand line, it has errors like this:
Traceback (most recent call last):
File "recur2.py", line 1, in ?
from recur1 import x
File "recur1.py", line 2, in ?
import recur2
File "recur2.py", line 2, in ?
from recur1 import y
ImportError: cannot import name y

What's really the problem here?

Thanks

Sep 9 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a

"Learning Python" <le*****************@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
An example in the book I didn't understood well
two modules files recursively import/from each other


There are past postings available in the archives (via Google) at least,
that lucided discuss circular imports. There are also some that recommend
"don't do that" and give alternatives. I recommend both.

Terry J. Reedy

Sep 9 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.