當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python matplotlib Substitution用法及代碼示例

本文簡要介紹 python 語言中 matplotlib.docstring.Substitution 的用法。

用法

class matplotlib.docstring.Substitution(*args, **kwargs)

基礎: object

對對象的文檔字符串執行 %-substitution 的裝飾器。

即使 obj.__doc__ 為 None(例如,如果 -OO 被傳遞給解釋器),這個裝飾器也應該是健壯的。

用法:構造一個 docstring.Substitution 用一個適合執行替換的序列或字典;然後用構造的對象裝飾一個合適的函數,例如:

sub_author_name = Substitution(author='Jason')

@sub_author_name
def some_function(x):
    "%(author)s wrote this function"

# note that some_function.__doc__ is now "Jason wrote this function"

也可以使用位置參數:

sub_first_last_names = Substitution('Edgar Allen', 'Poe')

@sub_first_last_names
def some_function(x):
    "%s %s wrote the Raven"

相關用法


注:本文由純淨天空篩選整理自skytowner.com大神的英文原創作品 matplotlib.docstring.Substitution。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。