# -*- coding: utf-8 -*-
def print_result(func):
def wrapper(*args, **kwargs):
rc = func(*args, **kwargs)
print('function ' + func.__name__ + ' returns ' + repr(rc))
return rc
return wrapper
@print_result
def a(x=0):
return x, x*x
print('a(2) =', a(2))
import random
random.seed()
MAXINT = 100
def get_even_rand():
x = random.randint(0, MAXINT//2)
yield x*2
>>> print get_even_rand().next()
56
>>> print get_even_rand().next()
62
>>> print get_even_rand().next()
94
>>> print get_even_rand().next()
90
>>> print get_even_rand().next()
16