python - 从 C++ PyBind11 中的另一个 Python 文件导入 Python 文件(模块)
问题描述
好的。因此,由于我在 Github 上的问题没有得到正确回答,并且有人建议我去一个合适的论坛,所以我来了。我正在尝试从另一个嵌入 PyBind11 的 Python 文件中导入 Python 文件。问题是这样的:
我有两个文件: mts.py:
def add(a, b):
return a + b
和main.py:
print('Hello, world!')
我有我的 C++ 代码:
py::initialize_interpreter(); // I am purposely not using eval_file because in the future I might not be using files, but strings instead.
py::exec(readFile("mts.py"));
py::exec(readFile("main.py"));
py::finalize_interpreter();
我的问题是,如何在“main.py”中导入“mts.py”?即我如何在'main.py'中调用'add'?
解决方案
推荐阅读
- java - 解析 JSON 异常 - 无法反序列化
- material-design - PreferenceFragments 中 DialogPreferences 的 MaterialAlertDialogBuilder
- java - 如何在 servlet 中获取 java bean 的值?
- crash - 已在 Play 商店发布,但应用无法打开
- java - 使用 android 应用程序扫描范围内的蓝牙设备
- django - 通过 cookie 标头发送令牌身份验证信息是否安全?
- android - 带有 Android 导航组件的通知单击侦听器
- java - 在线游戏的 Selenium 自动化
- java - 元素与 GridBagConstraints 不正确对齐
- c# - 如何在 Bot Framework C# 中在运行时生成瀑布步骤?