用法:
inspect.getcallargs(func, /, *args, **kwds)
將
args
和kwds
綁定到 Python 函數或方法func
的參數名稱,就像使用它們調用它一樣。對於綁定方法,還將第一個參數(通常命名為self
)綁定到關聯的實例。返回一個 dict,將參數名稱(包括*
和**
參數的名稱,如果有的話)映射到args
和kwds
的值。如果調用func
不正確,即每當func(*args, **kwds)
由於簽名不兼容而引發異常時,就會引發相同類型的異常和相同或相似的消息。例如:>>> from inspect import getcallargs >>> def f(a, b=1, *pos, **named): ... pass >>> getcallargs(f, 1, 2, 3) == {'a': 1, 'named': {}, 'b': 2, 'pos': (3,)} True >>> getcallargs(f, a=2, x=4) == {'a': 2, 'named': {'x': 4}, 'b': 1, 'pos': ()} True >>> getcallargs(f) Traceback (most recent call last): ... TypeError: f() missing 1 required positional argument: 'a'
3.2 版中的新函數。
自 3.5 版起已棄用:采用
Signature.bind()
和Signature.bind_partial()
反而。
相關用法
- Python inspect.Parameter.replace用法及代碼示例
- Python inspect.Parameter.kind用法及代碼示例
- Python inspect.Signature.from_callable用法及代碼示例
- Python inspect.isasyncgenfunction用法及代碼示例
- Python inspect.isawaitable用法及代碼示例
- Python inspect.BoundArguments.apply_defaults用法及代碼示例
- Python inspect.BoundArguments用法及代碼示例
- Python inspect.Parameter.kind.description用法及代碼示例
- Python inspect.formatargspec用法及代碼示例
- Python inspect.Signature.replace用法及代碼示例
- Python inspect.signature用法及代碼示例
- Python scipy integrate.trapz用法及代碼示例
- Python int轉exponential用法及代碼示例
- Python integer轉string用法及代碼示例
- Python scipy interpolate.CubicHermiteSpline.solve用法及代碼示例
- Python scipy interpolate.CubicSpline.solve用法及代碼示例
- Python int.from_bytes用法及代碼示例
- Python scipy integrate.cumtrapz用法及代碼示例
- Python scipy interpolate.PchipInterpolator.solve用法及代碼示例
- Python int.bit_length用法及代碼示例
注:本文由純淨天空篩選整理自python.org大神的英文原創作品 inspect.getcallargs。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。