ITPub博客

首页 > IT职业 > IT生活 > Python代码中编译是什么

Python代码中编译是什么

IT生活 作者:ywbair 时间:2021-09-11 09:56:27 0 删除 编辑

说明

1、在执行Python代码时,在Python解释器用四个过程“拆解”我们的代码,最终被CPU执行返回给用户。

2、当用户键入代码交给Python处理的时候会先进行词法分析,例如用户键入关键字或者当输入关键字有误时,都会被词法分析所触发,不正确的代码将不会被执行。

实例

#!/usr/bin/env python
import re
from time import ctime
def run():
        pattern='case'
        rere_obj=re.compile(pattern)
        infile=open('/etc/rc.subr','r')
        match_count=0
        lines=0
        for line in infile:
                match=re_obj.search(line)
                if match:
                        match_count+=1
                lines+=1
        return (lines,match_count)
if __name__=='__main__':
        print('starting at:',ctime())
        lines,match_count=run()
        print "LINES:",lines
        print "MATCHS:",match_count
        print('ending at:',ctime())

Python代码中编译的介绍,通过结尾的例子,我们可以看出编译后代码的性能是比较好的。大家学会后也赶快用起来吧。更多Python学习指路:python基础教程

本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/2056/viewspace-2830126/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-04-16

  • 博文量
    84
  • 访问量
    666