For objects with __dict__ vars() returns modifiable dict: >>> class A(): ... pass ... >>> a = A() >>> a.x = 42 >>> vars(a) {'x': 42} >>> vars(a)['x'] = 43 >>> vars(a)['y'] = 44 >>> a.x, a.y, vars(a) (43, 44, {'y': 44, 'x': 43}) For globals vars() returns modifiable dict: >>> x = 42 >>> vars()['x'] 42 >>> vars()['x'] = 43 >>> vars()['y'] = 44 >>> vars()['x'], vars()['y'] (43, 44) For locals vars() returns... hmm, partially modifiable dict: >>> def f(): ... x = 42 ... print(vars()) ... vars()['x'] = 43 ... vars()['y'] = 44 ... print(x, vars()) ... >>> f() {'x': 42} 42 {'y': 44, 'x': 42} Should behavior of vars() be corrected for locals? Should vars() for objects with __slots__ [1] returns modifiable or non-modifiable dict? [1] http://bugs.python.org/issue13290
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4