python之如何启动一个应用程序

很多初学者会有这样的思考,通过python编写代码,如何启动一个python编写的应用程序呢?
有过c/c++开发的朋友都知道:c/c++程序都会有一个main函数作为程序的入口函数。python是c语言开发的,作为更高级的语言,肯定是也是参考c/c++的方式来启动程序。谈到这里就不能绕过__main__。

对__main__的英文介绍如下:

'_main_' is the name of the scope in which top-level code executes. A module’s _name_ is set equal to '_main_' when read from standard input, a script, or from an interactive prompt.

A module can discover whether or not it is running in the main scope by checking its own _name_, which allows a common idiom for conditionally executing code in a module when it is run as a script or with python -m but not when it is imported:

中文含义是如下:

__main__是顶层代码执行环境的名字。当一个模块从标准输入,脚本或者解释器提示行中被读取时,模块的__name__属性被设置成__main__

模块可以依据检查__name__属性是

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值