相关疑难解决方法(0)

如何使用Python装饰器检查函数参数?

我想在调用一些函数之前定义一些通用装饰器来检查参数.

就像是:

@checkArguments(types = ['int', 'float'])
def myFunction(thisVarIsAnInt, thisVarIsAFloat)
    ''' Here my code '''
    pass
Run Code Online (Sandbox Code Playgroud)

附注:

  1. 类型检查就是在这里展示一个例子
  2. 我使用的是Python 2.7,但Python 3.0也很有趣

python python-decorators

28
推荐指数
4
解决办法
3万
查看次数

标签 统计

python ×1

python-decorators ×1