python之如何执行用字符串表示的代码
发布时间:2020-12-20 09:52:26 所属栏目:Python 来源:网络整理
导读:比如说现在有这么一段字符串,"print('helloworld')",那么怎么将其转换成python认识的格式运行? s= " print('helloworld') " r = compile(s, string " ,1)">exec ) exec (r) 输出:helloworld
比如说现在有这么一段字符串,"print('helloworld')",那么怎么将其转换成python认识的格式运行? s="print('helloworld')" r = compile(s,<string>",1)">exec) exec(r) 输出:helloworld (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |