我需要为一个函数创建decorator,这样,如果一个特定函数在一行中使用相同的参数调用了两次,它将不会运行,而是返回None
被修饰的函数可以有任意数量的参数,但不能有关键字参数
例如:
@dont_run_twice
def myPrint(*args):
print(*args)
myPrint("Hello")
myPrint("Hello") #won't do anything (only return None)
myPrint("Hello") #still does nothing.
myPrint("Goodbye") #will work
myPrint("Hello") #will work
看看这个简单的方法是否适合你
相关问题 更多 >
编程相关推荐