pybind11 - 如何将文档字符串传递给 pybind11::def_property_readonly?
问题描述
我正在尝试将记录在案的只读属性添加到使用 pybind11 定义的 python 扩展中的类中。通常这是通过在定义调用中添加一个字符串参数来完成的。但是,当我将字符串参数添加到只读属性定义调用时,会出现模板编译错误。
编译但没有文档字符串:
[...]
.def_property_readonly(
"property_name",
[](){ return ""; })
[...]
有一个文档字符串但不编译:
[...]
.def_property_readonly(
"property_name",
[](){ return ""; },
std::string("docstring"))
[...]
解决方案
你必须通过 aconst char *
而不是 a std::string
。
[...]
.def_property_readonly(
"property_name",
[](){ return ""; },
"const char docstring")
[...]
推荐阅读
- amazon-dynamodb - DynamoDB UpdateExpression A=B+C+D 使用单个请求
- pdf - 将 salesforce 闪电组件渲染为 pdf(生成 PDF)
- redux - Redux thunk,连接,应用中间件,
- javascript - 谷歌图表时间线标签显示在框外
- data-visualization - 如何在 Power BI 中根据用户隐藏可视化?
- php - 将 VB6 代码转换为 PHP
- apache-camel - Camel AWS SNS - 找不到主题
- ajax - 如何使用 ajax 从 go api 检索数据?
- python-2.7 - 使用 Python 删除文件中的行
- angular - 角材料数据表不显示一行