1. Make a script both importable and executable(使你的脚本可输入且可执行)
if __name__ == '__main__':
Example
def main():
print('Doing stuff in module', __name__)
if __name__ == '__main__':
print('Executed from the command line')
main()
$ python mymodule.py
Executed from the command line
Doing stuff in module __main__
>>> import mymodule
>>> mymodule.main()
Doing stuff in module mymodule