相关疑难解决方法(0)

__main__和python中的作用域

我有点惊讶于以下行为:

def main():
    print "%s" % foo

if __name__ == "__main__":
    foo = "bar"
    main()
Run Code Online (Sandbox Code Playgroud)

即模块函数可以访问封闭变量__main__.它的解释是什么?

python scope

29
推荐指数
4
解决办法
1万
查看次数

标签 统计

python ×1

scope ×1