Can "self" crush itself?

Steven D'Aprano steven at REMOVE.THIS.cybersource.com.au
Wed Nov 25 21:06:24 EST 2009


On Wed, 25 Nov 2009 20:09:25 -0500, Terry Reedy wrote:

> n00m wrote:
>>> Or just raise an exception in __init__(),..
>> 
>> Then we are forced to handle this exception outside of class code. It's
>> Ok. Never mind.
>> --------------------
>> 
>> Next thing.
>> I can't understand why we can get __name__, but not __dict__, on the
>> module level?
>> 
>> 
>> print __name__
>> print __dict__
> 
> If the global namespace contained itself, as a dict, there would be an
> infinite loop.


Why would that be a problem?  Any time you do this:

>>> g = globals()


you create such a recursive reference:

>>> globals()['g']['g']['g']['g'] is globals() is g
True


Yes, there's a tiny bit extra work needed when bootstrapping the 
processes, and when exiting, but I don't see why it's a big deal. Whether 
it's necessary or useful is another story.



-- 
Steven



More information about the Python-list mailing list