Ubuntu Pastebin

Paste from Chipaca at Wed, 16 Sep 2015 12:58:16 +0000

Download as text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
from functools import wraps

def once(f):
    @wraps(f)
    def wrapper(*a, **kw):
        if not f.has_run:
            f.has_run = True
            return f(*a, **kw)
    f.has_run = False
    return wrapper

@once
def f(a):
    print(a)

f("hi")
f("bye")
Download as text