Can "self" crush itself?

Mel mwilson at the-wire.com
Thu Nov 26 04:36:06 CET 2009


n00m wrote:

> 
> 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)

Because self is not in globals().

It's defined as a local symbol in Moo.__init__ , supplied to that function 
as the first parameter.

	Mel.





More information about the Python-list mailing list