python - 将一个文件命名为'__main__.py', 然后在其他文件import它,那么它的'__name__'会是什么?
伊谢尔伦
伊谢尔伦 2017-04-17 11:46:46
[Python讨论组]

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()
伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

全部回复(1)
PHPz

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

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号