简体   繁体   中英

How to use eval() in compiled python file?

I'm writing a tool in 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.

Is there any possibility to dynamically evaluate python code in exe application?

First, don't use exec or eval . They are inherently dangerous. Second, using those functions requires that the "compiled python file" include the entire python distribution; ie, "python installation" as mentioned in the py2exe documentation. 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. Those functions should only be used by tools like ipython to interactively explore the behavior of Python.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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