gpt4 book ai didi

python - 如果嵌入了 Python,如何从 C 执行 .py 脚本?

转载 作者:太空宇宙 更新时间:2023-11-04 07:29:37 26 4
gpt4 key购买 nike

我找不到这方面的相关信息。对于 lua,如果你想从 main() C 函数执行一个 test.lua 文件,你调用 lua_dofile("test.lua")。什么是 python 等价物?

最佳答案

如果嵌入 Python,请使用 PyRun_SimpleFile :

FILE *fp = fopen("test.py", "r");
int ret = PyRun_SimpleFile(fp, "test.py");
if(ret < 0) {
/* exception occurred */
}

关于python - 如果嵌入了 Python,如何从 C 执行 .py 脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15054446/

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