python的C扩展中的文档字符串? [英] Docstrings in C extensions to Python?

查看:113
本文介绍了python的C扩展中的文档字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在创建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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆