jzztf / wiki

wiki
https://jzztf.github.io
Other
1 stars 0 forks source link

py-`__name__`-`__main__` #18

Open jzztf opened 6 years ago

jzztf commented 6 years ago

关于 __name____main__

# 测试文件
#!/usr/bin/env python3

"""测试__name__ == '__main__'"""

def tester():
    print("this is main")

if __name__ == '__main__':
    tester()
=====================================
# shell
$ python3 test_name.py
this is main
$ python3
=====================================
# python3
>>> import test_name
>>> test_name.__name__
'test_name'