Rob*_*obM 2 python scope introspection
为什么创建/修改locals()的成员在函数内不起作用?
Python 2.5 (release25-maint, Jul 20 2008, 20:47:25)
[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> # Here's an example of what I expect to be possible in a function:
>>> a = 1
>>> locals()["a"] = 2
>>> print a
2
>>> # ...and here's what actually happens:
>>> def foo():
... b = 3
... locals()["b"] = 4
... print b
...
>>> foo()
3
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
691 次 |
| 最近记录: |