首先新建一个hello.py,只写一句代码:
hello.py
print(__name__)
1、在命令行直接调用运行:
`$ python hello.py`
`__main__`
2、在Python交互环境中加载模块:
`>>> import hello`
`hello`
牛逼!
牛逼!!!!!!!!!!!!!!
什么意思呀,没怎么理解
回复楼上,就是把在python交互环境里import该文件的__name__和直接打开的__name__区别告诉你,也就是import后的__name__是文件名
Sign in to make a reply
HellPlay
首先新建一个
hello.py
,只写一句代码:print(__name__)
1、在命令行直接调用运行:
`$ python hello.py`
`__main__`
2、在Python交互环境中加载模块:
`>>> import hello`
`hello`