我目前正在处理一个使用单独cli和gui的项目。GUI部分用C++编写,以保持可执行的小。我用pythSudio编译了python程序,需要从C++程序调用一些函数。p>
Python部分:
import configparser
def getconfig() -> list:
config = configparser.ConfigParser()
config.read("config.ini")
section1 = config["general"]
section2 = section["section2"]
return [section1, section2] #should be a list of dict?
通过pyinstaller--onefile--clean myprogram.py编译它
<>我想在C++中做的是://please correct me if this is the wrong type,
//i know i probably need to do a bit of parsing between python and C++ types
std::vector<std::unordered_map<std::string, std::string>> > = myprogram.getconfig()
<>我不想再做C++中的配置解析,或者你推荐它,因为调用编译的Python二进制可能比较容易?p>这个程序只需要在linux上运行,不需要windows
如果您仅计划在POSIX兼容系统(即GNU/Linux)上运行,则可以生成一个新进程来运行Python脚本,例如使用C函数
exec
。例如:然后在pythonscript.py中:
这个技巧也适用于bash脚本。 不过,脚本必须是可执行的,所以请记住运行
chmod +x pythonscript.py
编辑: 您可能需要使用管道或其他机制进行进程间通信。(这不是我的专长!)
相关问题 更多 >
编程相关推荐