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

发布于 2024-11-14 17:22:51 字数 149 浏览 3 评论 0 原文

创建 Python 的 C 扩展时,是否可以以某种方式编写公开为 docstrings 给扩展程序的用户?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

佞臣 2024-11-21 17:22:51

类型的文档字符串可以作为 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 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().

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文