嵌入Python设计

发布于 2024-08-10 01:59:04 字数 544 浏览 1 评论 0原文

有很多关于如何在应用程序中嵌入 python 的教程/说明,但没有关于如何使用嵌入式解释器并与应用程序交互的总体设计(我见过)。

我能想到的唯一想法就是简单地为用户提供在程序中执行脚本的方法(菜单选项等)。因此,某些类、函数、对象等将导出到 python,某些脚本会执行某些操作,然后可以从程序运行该脚本。

这样的设计会“安全”吗?这意味着恶意/编写不当的脚本是否可以“损坏”程序和/或计算机?我认为它可能取决于脚本可用的功能(例如:它可能会尝试覆盖一些重要文件等)如何防止这种情况发生? (例如:脚本认证、程序设计等)

这是特定于实现的,但是脚本的效果在运行完成后是否可能/可行?这意味着如果脚本计算某些内容,那么在脚本执行完成后结果是否可供程序使用?我认为如果程序被设置为与特定脚本交互是可能的,但该程序将在大多数脚本编写之前发布;这样的设置似乎是对嵌入脚本语言的滥用。实际上是否存在您希望脚本执行结果可用的情况,或者这是一种人为的情况,但实际上并没有发生?

还有其他嵌入 python 的设计吗?
以类似于插件架构的方式使用 python 怎么样?

谢谢,
马修·A·托德

There are lots of tutorials/instructions on how to embed python in an application, but nothing (that I've seen) on overall design for how the embedded interpreter should be used and interact with the application.

The only idea I could think of would be to simply give the user a method (menu option, etc) of executing scripts in the program. So certain classes, functions, objects, etc. would be exported to python, some script would do something, then said script could be run from the program.

Would such a design be "safe?" Meaning is it feasible for a malicious/poorly-written script to "damage" the program and/or computer? I assume its possible depending on the functions available to the script (e.g: it could try to overwrite some important files, etc.) How might one prevent such from happening? (e.g: script certification, program design, etc.)

This is implementation specific, but is it possible/feasible to have the effects of the script stay after its done running? Meaning if a script computes something, will the result be available to the program after execution of the script has finished? I think it is possible to do if the program were setup to interact with a specific script, but the program will be released before most scripts are written; and such a setup seems like a misuse of embedding a scripting language. Is there actually cases where you would want the result of a scripts execution to be available, or is this a contrived situation that doesn't really occur?

Are there any other designs for embedding python?
What about using python in a way similar to a plugin architecture?

Thanks,
Matthew A. Todd

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

べ繥欢鉨o。 2024-08-17 01:59:04

我能想到的唯一想法就是简单地为用户提供一种在程序中执行脚本的方法(菜单选项等)。

正确。

因此某些类、函数、对象等将导出到 python,某些脚本会执行某些操作,然后该脚本可以从程序运行。

正确。

这样的设计“安全吗?”

是的。除非你的用户是恶意的、精神病的反社会者。他们想让你的程序做有用的事情。他们首先购买/下载了该软件。他们认为它有价值。

他们信任您的软件。为什么不相信他们呢?

这意味着如果脚本计算某些内容,则在脚本执行完成后结果是否可供程序使用?

像 Apache 这样的程序总是这样做。你搞砸了配置(“脚本”),它崩溃了。吸取教训了吗?不要搞砸配置。

The only idea I could think of would be to simply give the user a method (menu option, etc) of executing scripts in the program.

Correct.

So certain classes, functions, objects, etc. would be exported to python, some script would do something, then said script could be run from the program.

Correct.

Would such a design be "safe?"

Yes. Unless your users are malicious, psychotic sociopaths. They want to make your program do useful things. They bought/downloaded the software in the first place. They think it has value.

They trusted your software. Why not trust them?

Meaning if a script computes something, will the result be available to the program after execution of the script has finished?

Programs like Apache do this all the time. You screw up the configuration ("script"), it crashes. Lesson learned? Don't screw up the configuration.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文