Python之exec()/compile()方法使用
来源:互联网 发布:青岛大学网络教学平台 编辑:程序博客网 时间:2024/05/10 11:50
# Python内置函数exec()可以用来执行Python代码# 或内置函数compile()编译的代码对象# exec程序中可写入python语法格式的代码,并直接输出。exec('print("Hello World!")')# compile(source, filename, mode[, flags[, dont_inherit]])# 中文说明:将source编译为代码或者AST对象。代码对象能够通过exec语句来执行或者eval()进行求值。# 参数source:字符串或者AST(Abstract Syntax Trees)对象。# 参数 filename:代码文件名称,如果不是从文件读取代码则传递一些可辨认的值。# 参数model:指定编译代码的种类。可以指定为 ‘exec’,’eval’,’single’。# 参数flag和dont_inherit:这两个参数暂不介绍,可选参数。code = "for i in range(0, 10): print(i)"cmpcode = compile(code, '', 'exec')exec(cmpcode)
运行结果
阅读全文
0 0
- Python之exec()/compile()方法使用
- python中eval, exec, execfile,和compile
- python中eval, exec, execfile,和compile
- python中eval, exec, execfile,和compile
- python中eval, exec, execfile,和compile
- python中eval, exec, execfile,和compile
- python中eval, exec, execfile,和compile
- python中eval, exec, execfile,和compile
- python中eval, exec, execfile,和compile
- python中eval, exec, execfile,和compile
- Python exec eval execfile compile 学习
- python中eval, exec, execfile,和compile
- python:exec eval execfile compile介绍
- python:exec eval execfile compile介绍
- python:exec eval execfile compile介绍
- python中eval, exec, execfile,和compile
- Python中的eval(),exec,execfile(),compile()
- python的exec, execfile,compile, eval
- 看点儿啥
- WAF与IPS的区别
- 什么时候JAVAbean
- Java并发编程实战 AQS(一):简介
- PhpStorm下Laravel5.2代码智能提示
- Python之exec()/compile()方法使用
- 面试总结字符串
- 解析json字符串
- eclipse重命名web项目名称,报错:Attribute "xmlns" was already specified for element "web-app"
- 疯狂java学习笔记
- hell 如何在bash脚本中连接两个字符串变量
- vue中对象属性改变视图不更新问题
- 观察者模式--农民的故事
- 统计学习方法笔记七----决策树