Circular package references
Alex Martelli
alex at magenta.com
Tue Aug 8 08:17:04 EDT 2000
"Serge Beaumont" <serge at sergebeaumont.com> wrote in message
news:398FED28.30250BAA at sergebeaumont.com...
> Hello all,
>
> I've looked everywhere: the docs, FAQs, dejanews and c.l.py. But I can't
> find an answer to my questions:
>
> - Are circular package references allowed in Python? I think not, from
> the exceptions I get... or there's something I'm not doing right.
They're allowed. E.g.:
D:\apy>python
Python 1.5.2 (#0, Apr 13 1999, 10:51:12) [MSC 32 bit (Intel)] on win32
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> import uno
>>> uno.fun()
Pak!
>>> import due
>>> due.fun()
Poook!
>>>
Where the packages are:
D:\apy>type uno.py
import due
pippo='Poook!'
def fun():
print due.pippo
D:\apy>type due.py
import uno
pippo='Pak!'
def fun():
print uno.pippo
D:\apy>
> - When two classes reference each other, MUST they be in the same
> package?
Not AFAIK.
> - I don't understand the global keyword either. Could this be a help
> here?
I doubt it; it's used inside a function or method to assert that a
certain variable, although (re-)bound there, refers to the package
namespace and not to the global one.
> My situation:
> thing.py -> class Thing -> imports allThings
> thinglist.py -> class ThingList -> imports Thing
> globals.py -> allThings (variable) -> imports ThingList
import allThings
is going to look for allThings.py, and
import Thing
is going to look for Thing.py, etc (all case-sensitive). Maybe
you just have the wrong names -- wrong case, globals.py rather
than allThings.py, etc?
Alex
More information about the Python-list
mailing list