本文簡要介紹 python 語言中 matplotlib._api.select_matching_signature
的用法。
-
選擇並調用接受
*args, **kwargs
的函數。funcs
是不應引發任何異常的函數列表(如果傳遞的參數與其簽名不匹配,則TypeError
除外)。select_matching_signature
嘗試使用*args, **kwargs
調用funcs
中的每個函數(按照給出的順序)。因TypeError
失敗的調用將被靜默跳過。一旦調用成功,select_matching_signature
就會返回其返回值。如果沒有函數接受*args, **kwargs
,則重新引發上次失敗調用引發的TypeError
。調用者通常應確保任何
*args, **kwargs
隻能綁定單個func
(以避免任何歧義),盡管select_matching_signature
不會檢查這一點。注意
select_matching_signature
旨在幫助實現簽名重載函數。一般來說,除了向後兼容性問題之外,應該避免使用此類函數。典型的使用模式是def my_func(*args, **kwargs): params = select_matching_signature( [lambda old1, old2: locals(), lambda new: locals()], *args, **kwargs) if "old1" in params: warn_deprecated(...) old1, old2 = params.values() # note that locals() is ordered. else: new, = params.values() # do things with params
它允許使用兩個參數(
old1
和old2
)或單個參數(new
)調用my_func
。請注意,新簽名是最後給出的,因此如果調用者傳入的參數與任何簽名都不匹配,則調用者會獲得與新簽名相對應的TypeError
。
用法
matplotlib._api.select_matching_signature(funcs, *args, **kwargs)
相關用法
- Python matplotlib semilogx用法及代碼示例
- Python matplotlib semilogy用法及代碼示例
- Python matplotlib subplots用法及代碼示例
- Python matplotlib silent_list用法及代碼示例
- Python matplotlib subplot2grid用法及代碼示例
- Python matplotlib step用法及代碼示例
- Python matplotlib subplot用法及代碼示例
- Python matplotlib savefig用法及代碼示例
- Python matplotlib axvspan用法及代碼示例
- Python matplotlib Axes.get_legend_handles_labels用法及代碼示例
- Python matplotlib AbstractMovieWriter用法及代碼示例
- Python matplotlib triplot用法及代碼示例
- Python matplotlib StarPolygonCollection.set_hatch用法及代碼示例
- Python matplotlib Axes.hist用法及代碼示例
- Python matplotlib boxplot用法及代碼示例
- Python matplotlib InsetPosition用法及代碼示例
- Python matplotlib ToolManager.toolmanager_disconnect用法及代碼示例
- Python matplotlib Figure.set_size_inches用法及代碼示例
- Python matplotlib figlegend用法及代碼示例
- Python matplotlib Axes.step用法及代碼示例
- Python matplotlib Axes.contour用法及代碼示例
- Python matplotlib LassoSelector用法及代碼示例
- Python matplotlib BrokenBarHCollection.set_hatch用法及代碼示例
- Python matplotlib Axes.plot用法及代碼示例
- Python matplotlib Axes.semilogx用法及代碼示例
注:本文由純淨天空篩選整理自skytowner.com大神的英文原創作品 matplotlib._api.select_matching_signature。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。