Closed GoogleCodeExporter closed 8 years ago
commandline.py version 610.
Original comment by ren...@gmail.com
on 1 Nov 2007 at 3:51
这两种情况应该输出什么?
import zhpy
a=1
zhpy.zh_exec("print a")
zhpy.zh_exec("print a", globals())
Original comment by ren...@gmail.com
on 2 Nov 2007 at 1:28
俺感觉除非 zhpy.zh_exec("print %(a)s", globals())
否则应该是一样的输出
print a
Original comment by Zoom.Quiet
on 2 Nov 2007 at 1:37
在zhpy1.2的时候, 执行的命名空间是一个单独的.
{{{
import zhpy
a=1
zhpy.zh_exec("print a")
#name 'a' is not defined
}}}
在有了zh_exec(code, global_ns, local_ns)的更改后,会有如下结果.
{{{
import zhpy
a=1
g_ns=globals()
zhpy.zh_exec("print a", g_ns)
#打印1
zhpy.zh_exec("a=2", g_ns)
print a
#打印2
zhpy.zh_exec("print a", g_ns)
#打印2
g2_ns={}
zhpy.zh_exec("b=1", g_ns)
print b
#b未定义
zhpy.zh_exec("print b", g_ns)
#打印1
zhpy.zh_exec("c=3")
zhpy.zh_exec("print c")
#打印3
zhpy.zh_exec("print globals()")
}}}
那么,是否这些结果符合Python和周蟒的设计思路?
尤其是在打印c的那部分,c的globals是在那个
命名空间又是在那里保存的?
Original comment by ren...@gmail.com
on 2 Nov 2007 at 1:59
Please have a test on the fix.
Original comment by ren...@gmail.com
on 3 Nov 2007 at 1:42
Original issue reported on code.google.com by
ren...@gmail.com
on 31 Oct 2007 at 4:36