from __future__ import generators def foo(): print 'hello' yield 1 print 'world' yield 2