Need a better understanding on how MRO works?

Alex Martelli aleax at mac.com
Sun Aug 26 17:52:56 CEST 2007


Steven W. Orr <steveo at syslang.net> wrote:
   ...
> =>accepts whatever dictionary you give it (so you can, though shouldn't,
> =>do strange things such as pass globals()...:-).
> 
> In fact, I wanted to make a common routine that could be called from 
> multiple modules. I have classes that need to be created from those 
> multiple modules. I did run into trouble when I created a common routine
> even though I passed globals() as one of the args. The """though 
> shouldn't""" is prompting me to ask why, and where I might be able to read
> more.

The dictionary you pass to new.classobj should be specifically
constructed for the purpose -- globals() will contains all sort of odds
and ends that have nothing much to do with the case.

You appear to be trying to embody lot of black magic in your "common
routine", making it communicate with its callers by covert channels; the
way you use globals() to give that routine subtle "side effects" (making
the routine stick entries there) as well as pass it an opaque,
amorphous, unknown blobs of input information, strongly suggests that
the magic is running away with you (a good general reference about that
is <http://video.google.com/videoplay?docid=4611491525028588899>).

"Explicit is better than implicit", "simple is better than complex",
etc, can be read by typing ``import this'' at an interactive Python
prompt.

The best book I know about the do's and don't's of large-scale software
architecture is Lakos' "Large-Scale C++ Software Design",
<http://www.amazon.com/Large-Scale-Software-Design-John-Lakos/dp/0201633
620> -- very C++ specific, but even though some of the issues only apply
to C++ itself, many of its crucial lessons will help with large scale SW
architecture in just about any language, Python included.

What I had to say about the lures and pitfalls of black magic in Python
specifically is spread through the Python Cookbook 2nd edition (and, to
a lesser extent, Python in a Nutshell).


Alex



More information about the Python-list mailing list