简体   繁体   English

如何在编译的python文件中使用eval()?

[英]How to use eval() in compiled python file?

I'm writing a tool in Python. 我正在用Python编写工具。 I want to compile it in exe, but there are several uses of exec() and eval() in code, which is not supported in exe files. 我想在exe中编译它,但是在代码中有exec()和eval()的几种用法,exe文件不支持。

Is there any possibility to dynamically evaluate python code in exe application? 有可能在exe应用程序中动态评估python代码吗?

First, don't use exec or eval . 首先,不要使用execeval They are inherently dangerous. 它们本质上是危险的。 Second, using those functions requires that the "compiled python file" include the entire python distribution; 其次,使用这些功能要求“编译的python文件”包含整个python发行版; ie, "python installation" as mentioned in the py2exe documentation. 即py2exe文档中提到的“ python安装”。 That isn't practical. 那是不切实际的。 Which is why you can't use those functions in a program "compiled" by such tools. 这就是为什么您不能在由此类工具“编译”的程序中使用这些功能的原因。

Even if you weren't trying to produce an executable from auto-py-to-exe or a similar tool you should not be using exec or eval in a production program. 即使您没有尝试从auto-py-to-exe或类似工具生成可执行文件,也不应在生产程序中使用execeval Those functions should only be used by tools like ipython to interactively explore the behavior of Python. 这些功能只能由ipython类的工具使用,以交互方式探索Python的行为。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM