簡體   English   中英

Sphinx 文檔:如何引用 Python 屬性?

[英]Sphinx documentation: how to reference a Python property?

如何引用用@property裝飾的方法?

對於簡單的方法, :py:meth:工作正常,但不適用於屬性:它不會創建指向它們的鏈接。

您應該改用:py:attr: 這個例子對我來說很好用:

class SomeClass(object):
    """This is the docstring of SomeClass."""

    @property
    def some_property(self):
        """This is the docstring of some_property"""
        return None

    def some_method(self):
        """This is the docstring of some_method.

        And this is a reference to :py:attr:`~some_property`
        """

這對我有用。 它使用正確的鏈接呈現MyClass.my_prop

:attr:`.MyClass.my_prop`

這僅呈現my_prop ,具有相同的鏈接。

:attr:`~.MyClass.my_prop`

我使用:py:obj:代替。

:py:attr:當該屬性在另一個頁面中時,對我不起作用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM