gpt4 book ai didi

python - 将 Python 脚本实现为 C++

转载 作者:太空宇宙 更新时间:2023-11-04 13:53:40 24 4
gpt4 key购买 nike

我正在使用动态脚本在 Python 中创建一个应用程序,允许用户创建自己的 Python 脚本并操作该应用程序。我宁愿用 c++ 制作应用程序,但我也想要自定义 Python 脚本操作。所以...基本上我需要 c++ 来读取和执行 Python 脚本。有办法做到这一点吗?

最佳答案

是的,你会想看看Embedding Python in Another Application .这是来自 "Very High Level Embedding" 的示例来自 python 文档。

#include <Python.h>

int
main(int argc, char *argv[])
{
Py_SetProgramName(argv[0]); /* optional but recommended */
Py_Initialize();
PyRun_SimpleString("from time import time,ctime\n"
"print 'Today is',ctime(time())\n");
Py_Finalize();
return 0;
}

关于python - 将 Python 脚本实现为 C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22497532/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com