【发布时间】:2023-01-26 19:05:10
【问题描述】:
我正在开发一个项目,其中大部分代码是 C++ 代码,一些是 python 代码。
有没有办法从 C++ 调用 import xxx 和/或 import xxx as x?
我会期待这样的事情:
auto other_mod = boost::python::import("the_other_module");
BOOST_PYTHON_MODULE(pystuff)
{
boost::python::module_<other_mod>("wrapping_name"); // I just invented this
}
然后在 python 中能够:
from pystuff import wrapping_name as wn
wn.someFunction()
请注意,我不想在 python 中执行此操作
import pystuff
import the_other_module
the_other_module 中的对象与 pystuff 中的对象具有相似的目标和依赖关系,因此我不希望用户有一个没有另一个。
我也知道我可以接受每个对象来自the_other_module,我想公开和包装,但我不想一一做。
【问题讨论】: