python的C扩展中的文档字符串? [英] Docstrings in C extensions to Python?
问题描述
在创建Python的C扩展时,是否有可能以某种方式编写以文档字符串给扩展名的用户?
类型的文档字符串可以作为文档中的示例.
功能的文档字符串可以包含在ml_doc
字段="nofollow noreferrer">模块的方法表.如果您希望文档字符串在物理上与实际函数接近",则可以在函数定义上方包括在方法表中引用的字符串常量.
模块的文档字符串可以作为参数传递给 Py_InitModule3()
或 Py_InitModule4()
函数.
更新:Python3不支持Py_InitModule3()
,该方法已替换为docstrings to users of the extension?
Docstrings for types can be included as the tp_doc
member in the PyTypeObject
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()
or Py_InitModule4()
functions.
UPDATE: Python3 does not support Py_InitModule3()
, and the method has been replaced with PyModule_Create()
.
这篇关于python的C扩展中的文档字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!