Friday, December 3, 2010

class keyword assigns to a variable

>>> g = 1
>>> def f():
...    global g
...    class g(): pass
...
>>> g
1
>>> f()
>>> g
<class __main__.g at 0x7f552b3f3650>

The class keyword in python is exactly equivalent to a call to the type function, even down to how it interacts with the global keyword.

No comments:

Post a Comment