其中if __name__=="__main__":表示的就是主函数的所在。
shell的运行结果 >>> import hello>>> hello.foo()function>>> hello.__name__'hello'>>>shell的运行结果表明当前命令行所指变量对应的属性信息,而当该文件以模块格式导入时,该模块导入的属性为该文件的名字。
自动执行的代码Python使用的是缩进对齐组织代码,即未缩进的部分将在载入时直接执行,因而不必有main函数。
import os,sysimport time print("Hello python !!!") def func_print():print("in func_print") def main():print("In main") #main()func_print()运行结果:
$ ./main2.py Hello python !!!in func_print