C 中的文档字符串扩展为 Python?
创建 Python 的 C 扩展时,是否可以以某种方式编写公开为 docstrings 给扩展程序的用户?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
创建 Python 的 C 扩展时,是否可以以某种方式编写公开为 docstrings 给扩展程序的用户?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(1)
类型的文档字符串可以作为
PyTypeObject
结构中的tp_doc
成员,请参阅文档中的示例。函数的文档字符串可以包含在 < 模块的方法表。如果您希望文档字符串“物理上接近”实际函数,则可以在方法表中引用的函数定义上方包含字符串常量。
方法的文档字符串可以分配给< 类型成员中的 code>doc 字段表。
模块的文档字符串可以作为参数传递给
Py_InitModule3()
或Py_InitModule4()
函数。更新:Python3不支持
Py_InitModule3()
,该方法已替换为PyModule_Create()
。Docstrings for types can be included as the
tp_doc
member in thePyTypeObject
structure, see an example in the docs.Docstrings for functions can be included in the
ml_doc
field of the module's method table. If you want your docstrings to be "physically close" to the actual functions, you could include string constants above your function definitions which you reference in the method table.Docstrings for methods can be assigned to the
doc
field in the type's member table.Docstrings for modules can be passed as a parameter to the
Py_InitModule3()
orPy_InitModule4()
functions.UPDATE: Python3 does not support
Py_InitModule3()
, and the method has been replaced withPyModule_Create()
.