lemonEX / zhpy

Automatically exported from code.google.com/p/zhpy
0 stars 0 forks source link

Name speace issue #21

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
Sample program echo.py:
{{{
#!/usr/bin/python
# encoding:utf-8
x =3
def echo():
    print x

if __name__ == '__main__':
    echo()
}}}

What is the expected output? What do you see instead?
python echo.py
3

zhpy echo.py
nothing output.

zhpy cmd shell,
import echo
echo.echo()
3

Please use labels and text to provide additional information.

Original issue reported on code.google.com by ren...@gmail.com on 31 Oct 2007 at 4:36

GoogleCodeExporter commented 8 years ago
commandline.py version 610.

Original comment by ren...@gmail.com on 1 Nov 2007 at 3:51

GoogleCodeExporter commented 8 years ago
这两种情况应该输出什么?
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

GoogleCodeExporter commented 8 years ago
俺感觉除非 zhpy.zh_exec("print %(a)s", globals())
否则应该是一样的输出
print a

Original comment by Zoom.Quiet on 2 Nov 2007 at 1:37

GoogleCodeExporter commented 8 years ago
在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

GoogleCodeExporter commented 8 years ago
Please have a test on the fix.

Original comment by ren...@gmail.com on 3 Nov 2007 at 1:42