<<Python编程实践>>之which is __main__

来源:互联网 发布:苹果下歌用什么软件 编辑:程序博客网 时间:2024/06/06 05:25

源代码文件

1.test_main.py

#!/usr/bin/pythonif __name__ == "__main__":print "I am the main program."else:print "Someone is importing me."

运行结果:



2.echo.py

#!/usr/bin/pythonimport test_mainprint "echo: __name__ is", __name__

运行结果:



3.import_echo.py

#!/usr/bin/pythonimport echoprint "After import, __name__ is", __name__, "and echo.__name__ is", echo.__name__

运行结果:


0 0
原创粉丝点击