网站首页 > 基础教程 正文
英文文档
compile(source, filename, mode, flags=0, dont_inherit=False, optimize=-1)
Compile the source into a code or AST object. Code objects can be executed by exec() or eval(). source can either be a normal string, a byte string, or an AST object. Refer to the ast module documentation for information on how to work with AST objects.
The filename argument should give the file from which the code was read; pass some recognizable value if it wasn’t read from a file (‘<string>’ is commonly used).
The mode argument specifies what kind of code must be compiled; it can be ‘exec’ if source consists of a sequence of statements, ‘eval’ if it consists of a single expression, or ‘single’ if it consists of a single interactive statement (in the latter case, expression statements that evaluate to something other than None will be printed).
compile()
1、将source编译为代码或者AST对象。代码对象能够通过exec语句来执行或者eval()进行求值。
2、参数source:字符串或者AST(Abstract Syntax Trees)对象。即需要动态执行的代码段。
3、参数 filename:代码文件名称,如果不是从文件读取代码则传递一些可辨认的值。当传入了source参数时,filename参数传入空字符即可。
4、参数mode:指定编译代码的种类,可以指定为 ‘exec’,’eval’,’single’。当source中包含流程语句时,mode应指定为‘exec’;当source中只包含一个简单的求值表达式,mode应指定为‘eval’;当source中包含了交互式命令语句,mode应指定为’single’。
>>> #流程语句使用exec
小结
希望通过上面的操作能帮助大家。如果你有什么好的意见,建议,或者有不同的看法,我都希望你留言和我们进行交流、讨论。
欢迎关注公号,访问更多精彩:AiryData。
如需转载,请联系授权,谢谢合作。
猜你喜欢
- 2024-10-12 python代码是如何执行的? python的代码如何运行
- 2024-10-12 deepin os下使用Geany编写python程序
- 2024-10-12 扩展和嵌入 Python 之重定向输出与编译
- 2024-10-12 python爬虫数据匹配-正则(re模块的用法)
- 2024-10-12 Python中的.pyc文件是干什么的呢?
- 2024-10-12 解锁 Python 中的正则表达式:轻松搞定文本处理
- 2024-10-12 Python 的底层 — 解释器和内存管理,你了解多少
- 2024-10-12 python程序执行原理 描述python程序执行原理
- 2024-10-12 这些 python 技巧,不知道就 out 了
- 2024-10-12 “挑战用 500 行 Python 写一个 C 编译器”
- 最近发表
- 标签列表
-
- gitpush (61)
- pythonif (68)
- location.href (57)
- tail-f (57)
- pythonifelse (59)
- deletesql (62)
- c++模板 (62)
- css3动画 (57)
- c#event (59)
- linuxgzip (68)
- 字符串连接 (73)
- nginx配置文件详解 (61)
- html标签 (69)
- c++初始化列表 (64)
- exec命令 (59)
- canvasfilltext (58)
- mysqlinnodbmyisam区别 (63)
- arraylistadd (66)
- node教程 (59)
- console.table (62)
- c++time_t (58)
- phpcookie (58)
- mysqldatesub函数 (63)
- window10java环境变量设置 (66)
- c++虚函数和纯虚函数的区别 (66)