我正在寻找一种高效的方法来检查Python函数的变量。例如,我想检查参数类型和值。是否有适用于此的模块?或者应该使用像装饰器这样的东西,或者任何特定的习惯用法吗?
def my_function(a, b, c):
"""An example function I'd like to check the arguments of."""
# check that a is an int
# check that 0 < b < 10
# check that c is not an empty string
isinstance
,并引发TypeError异常。 - bruno desthuilliersreturn func(a, b, c)
? - glglgl