Python内置函数
- Python内置函数- __import__() 函数
- Python内置函数- zip()函数
- Python内置函数-vars()函数
- Python内置函数-type()函数
- Python内置函数-tuple 函数
- Python内置函数-super()函数
- Python内置函数-sum()函数
- Python内置函数-str()函数
- Python内置函数-staticmethod()函数
- Python内置函数-sorted()函数
- Python内置函数-slice()函数
- Python内置函数-setattr()函数
- Python内置函数-set() 函数
- Python内置函数-round()函数
- Python内置函数-reversed函数
- Python内置函数-repr()函数
- Python内置函数-range() 函数
- Python内置函数-property() 函数
- Python内置函数-print() 函数
- Python内置函数-pow() 函数
- Python内置函数-ord()函数
- Python内置函数-open()函数
- Python内置函数-oct() 函数
- Python内置函数-next() 函数
- Python内置函数-min() 函数
- Python内置函数-memoryview() 函数
- Python内置函数-max() 函数
- Python内置函数-map()函数
- Python内置函数-locals() 函数
- Python内置函数-list()函数
- Python内置函数-len()函数
- Ptyhon内置函数-iter()函数
- Python内置函数-issubclass()函数
- Python内置函数-isinstance() 函数
- Python内置函数-int() 函数
- Python内置函数-input()函数
- Python内置函数-id()函数
- Python内置函数-hex()函数
- Python内置函数-help()函数
- Python内置函数-hash() 函数
- Python内置函数-hasattr() 函数
- Python内置函数-globals() 函数
- Python内置函数-getattr() 函数
- Python内置函数-frozenset() 函数
- Python内置函数-format()函数
- Python内置函数-float()函数
- Python内置函数-filter()函数
- Python内置函数-exec()函数
- Python内置函数-eval()函数
- Python内置函数-enumerate() 函数
- Python内置函数-divmod()函数
- Python内置函数-dir()函数
- Python内置函数-dict()函数
- Python内置函数- delattr()函数
- Python内置函数-complex()函数
- Python内置函数-compile() 函数
- Python内置函数-classmethod()函数
- Python内置函数-chr() 函数
- Python内置函数-callable() 函数
- Python内置函数-bytes函数
- Python内置函数-bytearray() 函数
- Python内置函数-bool()函数
- Python内置函数-bin() 函数
- Python内置函数-ascii()函数
- Python内置函数-any() 函数
- Python内置函数-all() 函数
- Python内置函数-abs() 函数
- Python内置函数-大全
Python内置函数-compile() 函数
Python3内置函数--compile() 函数
compile() 函数描述:
compile() 函数将一个字符串编译为字节代码。
compile() 函数语法:
compile(source, filename, mode[, flags[, dont_inherit]])
compile() 函数参数:
source -- 字符串或者AST(Abstract Syntax Trees)对象。
filename -- 代码文件名称,如果不是从文件读取代码则传递一些可辨认的值。
mode -- 指定编译代码的种类。可以指定为 exec, eval, single。
flags -- 变量作用域,局部命名空间,如果被提供,可以是任何映射对象。
flags和dont_inherit是用来控制编译源码时的标志
compile() 函数返回值:
返回表达式执行结果。
compile() 函数实例:
str = "for i in range(0,10): print(i,end='')" c = compile(str,'','exec') # 将字符串str编译为字节代码对象 print(type(c)) # <class 'code'> print(c) # <code object <module> at 0x7efc458eb4b0, file "", line 1> exec(c) # 0123456789 str_list = '2*4-5' c_list = compile(str_list,'','eval') # 将字符串str_list编译为字节代码对象 print(type(c_list)) # <class 'code'> print(c_list) #<code object <module> at 0x7f133010b780, file "", line 1> print(eval(c_list)) # 3 s_str = "print('python中文网')" c_s = compile(s_str,'','single') # 将字符串str编译为字节代码对象 print(type(c_s)) # <class 'code'> print(c_s) # <code object <module> at 0x7fe14ee04780, file "", line 1> exec(c_s) # python中文网
最后修改:2020年3月19日 21:58