Import File Madness

Andrew Dalke dalke at acm.org
Thu Apr 27 04:28:58 EDT 2000


jsolbrig at my-deja.com asked several questions/comments on the import
statement
>1: Once a python application is large and various classes have static
member
>objects of different types, import statements seem to have a similar logic
to
>C include files. I.E., the question of what order to do the include becomes
>non-trivial. Is there anyway around this or ways to escape this?


That's in the FAQ, at http://www.python.org/doc/FAQ.html#4.37

It basically says, don't do it.  Usually there are ways around it, though
it's harder with class variables.

A tricky way, if you really want to play nasty, is to override
__getattr__, as in:

 class Spam:
   def __getattr__(self, key):
     if name == "class_variable":
       Spam.class_variable = other_package.property
       return other_package.property
     raise AttributeError, key


Can't really help with the other 3 questions.  Haven't seen those
problems.

                    Andrew
                    dalke at acm.org






More information about the Python-list mailing list