1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| >>> def unefunc():
... if 'mavar' in dir(unefunc):
... unefunc.mavar += 1
... else:
... unefunc.mavar = 0
... print unefunc.mavar
...
>>> unefunc()
0
>>> unefunc()
1
>>> unefunc()
2
>>> def uneautre():
... print unefunc.mavar
...
>>> uneautre()
2
>>> print dir(unefunc)
['__call__', '__class__', '__closure__', '__code__', '__defaults__', '__delattr__', '__dict__', '__doc__', '__format__', '__get__', '__getattribute__', '__globals__', '__hash__', '__init__', '__module__', '__name__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'func_closure', 'func_code', 'func_defaults', 'func_dict', 'func_doc', 'func_globals', 'func_name', 'mavar'] |
Partager