When I need to print variables, I tend to be lazy and use "{someVariable}".format( **locals() )
a lot. For example:
x = 10
[ "{x} {i}".format( **locals() ) for i in xrange(3) ]
Out:
['10 0', '10 1', '10 2']
But now if I use a generator instead:
x = 10
for y in ( "{x} {i}".format( **locals() ) for i in xrange(3) ) :
print y
Out:
KeyError: 'x'
Oh no! What happened?