Need a better understanding on how MRO works?

Steven W. Orr steveo at syslang.net
Sun Aug 26 07:55:39 EDT 2007


On Saturday, Aug 25th 2007 at 22:14 -0700, quoth Alex Martelli:

=>Steven W. Orr <steveo at syslang.net> wrote:

=>> * Also, I'd like to understand what the difference is between 
=>>     nclass = new.classobj(name,(D1,),globals())
=>> vs. 
=>>     def classfactory():
=>>       class somename(object):
=>>           def somestuff():
=>>               pass
=>>         return somename
=>>     G1 = classfactory()
=>>     globals()[name] = G1
=>> 
=>> Does new.classobj do anything special?
=>
=>No, new.classobj does essentially the same thing that Python does after
=>evaluating a class statement to prepare the class's name, bases and
=>dictionary: finds the metaclass and calls it with these arguments.
=>
=>A key difference of course is that a class statement prepares the class
=>dictionary as a new, ordinary, distinct dictionary, while new.classobj
=>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.

-- 
Time flies like the wind. Fruit flies like a banana. Stranger things have  .0.
happened but none stranger than this. Does your driver's license say Organ ..0
Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
individuals! What if this weren't a hypothetical question?
steveo at syslang.net



More information about the Python-list mailing list