Can "self" crush itself?

n00m n00m at narod.ru
Thu Nov 26 03:39:09 CET 2009


aaah... globals()...
Then why "self" not in globals()?

class Moo:
    cnt = 0
    def __init__(self, x):
        self.__class__.cnt += 1
        if self.__class__.cnt < 3:
            self.x = x
        else:
            print id(self)
            for item in globals().items():
                print item

f = Moo(1)
g = Moo(2)
h = Moo(3)


>>> ===================================== RESTART ====
>>>
13407336
('g', <__main__.Moo instance at 0x00CC9260>)
('f', <__main__.Moo instance at 0x00CC9440>)
('__builtins__', <module '__builtin__' (built-in)>)
('Moo', <class __main__.Moo at 0x00CCC060>)
('__name__', '__main__')
('__doc__', None)
>>>



More information about the Python-list mailing list