6. Modules If you quit from the Python interpreter and enter it again, the definitions you have made (functions and variables) are lost. Therefore, if you want to write a somewhat longer program, you are better off using a text editor to prepare the…
因为Python模块在被导入时,定义在模块中的顶级代码是会被执行的!如果我们想改变这种运行方向可以这样做: if __name__ == '__main__':#当这个模块作为主程序时__name__的值就会等于'__main__',当被别人调用的时__name__等于这个模块的名字. print 'Will enter module1.main';else: print'Will enter module1.test';…