python中if __name__ == ‘__main__’是什么意思
__,python,if,name,main,什么,意思
2025-04-07 09:01:27 时间
大家好,又见面了,我是你们的朋友全栈君。
执行当前文件中: __name__ == ‘__main__’ 是返回true,引用模块中的则返回false
如:现在有两python文件,one.py 和 two.py
# file one.py
def func():
print("func() in one.py")
print("top-level in one.py")
if __name__ == "__main__":
print("one.py is being run directly")
else:
print("one.py is being imported into another module")
# file two.py
import one
print("top-level in two.py")
one.func()
if __name__ == "__main__":
print("two.py is being run directly")
else:
print("two.py is being imported into another module")
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/156109.html原文链接:https://javaforall.cn
相关文章
- Python的抽象魔法--类
- python小知识点-exec的local
- Python求解两数之和[通俗易懂]
- python中delay__python delay函数「建议收藏」
- python画图函数
- XGBoost:在Python中使用XGBoost
- X波段双极化相控阵天气雷达基数据的python读取方法
- Python || 皖事通安康码截图信息简易识别采集
- 情人节来了,教你个用 Python 表白的技巧「建议收藏」
- Magic * in Python
- Python 一网打尽<排序算法>之从希尔排序聊聊分治算法的哲学
- Python二级考试知识点(史上最全)
- 使用Python检测符号及乱码字符
- python的random()函数用法_Python随机函数random用法示例
- python爬取豆瓣电影榜单
- 用Python做个色情图片识别
- Python中的下划线
- python实现二叉树层序遍历(逐层打印二叉树)「建议收藏」
- Android 平台的Python——基础篇(一)
- Python画图显示中文