Cross-reference 'import' in a class hierarchy

Greg Ewing (using news.cis.dfn.de) ckea25d02 at sneakemail.com
Tue Apr 8 07:34:33 CEST 2003


Jeremy Bowers wrote:
> IMHO, this is the largest wart by far in Python when it comes to writing
> "real" programs that really shouldn't have every file dumped into the same
> directory.

It's actually not so bad in the case of an *application*,
because if you structure your application like this:

     myapp.py
     MyAppPkg
        __init__.py
        mymodule1.py
        mymodule2.py
        MySubPkg
          __init__.py
          mymodule3.py

etc., then when you do

   python myapp.py

the directory containing myapp.py effectively becomes a
source of top-level packages for the duration, so you can
refer to MyAppPkg.mymodule1 etc.

It's more of a problem when, e.g. you want to embed a
library as a subpackage of another library, and the
embedded library itself consists of subpackages which
would like to refer to each other without having to
care where they reside in the global picture.

-- 
Greg Ewing, Computer Science Dept,
University of Canterbury,	
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg





More information about the Python-list mailing list