from __future__ import generators def foo(n): if (n < 3): yield 1 else: return yield 2