将字符串编译成python 能识别或可执行的代码
s="print('hello world')"
r=compile(s,"<string>","exec")
print(r)
exec(r)
out:
<code object <module> at 0x7f08133268a0, file "<string>", line 1>
hello world
将字符串编译成python 能识别或可执行的代码
s="print('hello world')"
r=compile(s,"<string>","exec")
print(r)
exec(r)
out:
<code object <module> at 0x7f08133268a0, file "<string>", line 1>
hello world
本文标题:python数据分析基础(15)-字符串编译成可执行代码
本文链接:https://www.haomeiwen.com/subject/druumhtx.html
网友评论