module Cyclic references

Emile van Sebille emile at fenx.com
Sun Jan 6 15:07:41 EST 2002


"Karthik Gurumurthy" <karthikg at aztec.soft.net> wrote in message
news:mailman.1010341632.10280.python-list at python.org...
> hi all,
> my code is behaving in a strange way.
>
> I have 4 modules
>
> test.py -- > from movie import Movie, Rental
> movie.py --> has 2 classes Movie , Rental
> #needs price and hence does
> import price
> price.py --> needs Movie
> #does
> from movie import Movie, Rental
> cust.py  --> has one class Customer
>
> so this is the sequence.
>
> test-->loads movie --> load price which in turn needs movie.
>
> Can someone tell me what's wrong here??
>
> >>> import test
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
>   File "test.py", line 1, in ?
>     from movie import Movie, Rental
>   File "movie.py", line 1, in ?

movie starts up and before anything is defined in the namespace, it does

>     import price
>   File "price.py", line 1, in ?

which then tries to get a reference from movie to Movie and Rental

>     from movie import Movie, Rental
> ImportError: cannot import name Movie

But movie itself is still staring up and has not yet defined Movie

You'll need to restructure in light of this dependency problem.  One way
might be to relocate price in movie.

HTH,

--

Emile van Sebille
emile at fenx.com

---------




More information about the Python-list mailing list