python的本地变量,全局变量,函数的作用域,嵌套函数引用包装函数

来源:互联网 发布:php导入excel到数据库 编辑:程序博客网 时间:2024/06/05 05:55
#!/usr/bin/python## Author:Tom# Date:2017/04/13# Email:bluelovelydog@gmail.com# Test:function scopedef test_func_scope(m):    a = 1    def b():        print"a:%s" % str(a)    print(locals())    print(globals())    return b()if __name__ == '__main__':    test_func_scope(1)


{'a': 1, 'b': <function b at 0x7f2baa8c51b8>, 'm': 1}
{'test_func_scope': <function test_func_scope at 0x7f2baa8c5140>, '__builtins__': <module '__builtin__' (built-in)>, '__file__': 'value.py', '__package__': None, '__name__': '__main__', '__doc__': None}
a:1


0 0
原创粉丝点击