开发者社区 问答 正文

python必备内置函数-complie()  

python必备内置函数-complie()

展开
收起
请回答1024 2020-03-30 11:17:07 490 分享 版权
1 条回答
写回答
取消 提交回答
  • 将字符串编译成python 能识别或可以执行的代码,也可以将文字读成字符串再编译。

    In [74]: s  = "print('helloworld')"
    
    In [75]: r = compile(s,"<string>", "exec")
    
    In [76]: r
    Out[76]: <code object <module> at 0x0000000005DE75D0, file "<string>", line 1>
    
    In [77]: exec(r)
    helloworld
    
    2020-03-30 11:17:19
    赞同 展开评论
问答分类:
问答地址: