Can "self" crush itself?

Steven D'Aprano steven at REMOVE.THIS.cybersource.com.au
Thu Nov 26 04:33:05 CET 2009


On Wed, 25 Nov 2009 18:39:09 -0800, n00m wrote:

> aaah... globals()...
> Then why "self" not in globals()?
> 
> class Moo:
>     cnt = 0
>     def __init__(self, x):
>         self.__class__.cnt += 1


Because it isn't a global, it's a local -- it is defined inside a class. 
Inside functions and classes, names you create are local, not global, 
unless you declare them global.




-- 
Steven



More information about the Python-list mailing list