我正在为接受文件指针的c++类编写python绑定-
PYBIND11_MODULE(pywrapper, m) {
...
py::class_<Dog, Animal>(m, "Dog")
.def(py::init<FILE * const>());
}
我这样调用c++函数-
f = open("test.log","w")
c = Dog(f)
我得到了一个预期的错误-
File "main.py", line 6, in test_init
client = Dog(f)
TypeError: __init__(): incompatible constructor arguments. The following argument types are supported:
1. pywrapper.Dog(arg0: _IO_FILE)
Invoked with: <_io.TextIOWrapper name='test.log' mode='w' encoding='UTF-8'>
如何在这里为构造函数编写包装器?你知道吗
我相信pybind11中没有实现输入缓冲区。下面是输出缓冲区https://github.com/pybind/pybind11/blob/master/include/pybind11/iostream.h#L24的实现
以下是缓冲区用作输出流的示例:
相关问题 更多 >
编程相关推荐