import导入__xxx__.py文件,它的'__name__'是什么,__xxx__.py__name__,python 版本2.7


python 版本2.7.2

__main__.py 文件内容如下

print '__name__ is ' + __name__

test_import.py 文件内容如下

import __main__

cmd 执行 python test_import.py

输出空空如也 求解


好吧,这是一个很小白的问题.

http://docs.python.org/2/library/main.html
This module represents the (otherwise anonymous) scope in which the interpreter’s main program executes — commands read either from standard input, from a script file, or from an interactive prompt. It is this environment in which the idiomatic “conditional script” stanza causes a script to run:

if __name__ == "__main__":    main()

你看看你 import 进来的那个 __main__ 是什么 =w=

编橙之家文章,

评论关闭