简体   繁体   English

C 中的文档字符串扩展为 Python?

[英]Docstrings in C extensions to Python?

When creating a C extension to Python, is it possible to be able to somehow write comments that are exposed as docstrings to users of the extension?在为 Python 创建 C 扩展时,是否能够以某种方式编写作为文档字符串公开给扩展用户的注释?

Docstrings for types can be included as thetp_doc member in the PyTypeObject structure, see an example in the docs .类型的文档字符串可以作为tp_doc成员包含在PyTypeObject结构中,请参阅文档中的示例

Docstrings for functions can be included in the ml_doc field of the module's method table .函数的文档字符串可以包含在模块方法表ml_doc字段中。 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.如果您希望您的文档字符串“物理上接近”实际功能,您可以在方法表中引用的 function 定义上方包含字符串常量。

Docstrings for methods can be assigned to the doc field in the type's member table .方法的文档字符串可以分配给类型的成员表中的doc字段。

Docstrings for modules can be passed as a parameter to the Py_InitModule3() or Py_InitModule4() functions.模块的文档字符串可以作为参数传递给Py_InitModule3()Py_InitModule4()函数。


UPDATE : Python3 does not support Py_InitModule3() , and the method has been replaced with PyModule_Create() .更新:Python3 不支持Py_InitModule3() ,该方法已被PyModule_Create()取代。

I don't think so, but you should be able to manipulate the docstrings of those objects from python.我不这么认为,但您应该能够从 python 操作这些对象的文档字符串。 See the python docs for more.有关更多信息,请参阅python 文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM