# HG changeset patch # User Jeff Hammel # Date 1314045508 25200 # Node ID 8006938c33acb6825b733b148faf9dd9e461e3e4 # Parent eb004971800158ea9d5e3916db20c319e253edd7 add fireonce decorator example diff -r eb0049718001 -r 8006938c33ac python/fireonce.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/python/fireonce.py Mon Aug 22 13:38:28 2011 -0700 @@ -0,0 +1,15 @@ +class fireonce(object): + def __init__(self, func): + self.func = func + def __call__(self, *args, **kwargs): + if not self.func: + return None + retval = self.func(*args, **kwargs) + self.func = None + +@fireonce +def foo(x): + print x + +foo('bar') +foo('fleem') # not printed