C
cokofreedom
if __name__ == '__main__':
print "Globals (For Loop):"
try:
for i in globals():
print "\t%s" % i
except RuntimeError:
print "Only some globals() printed\n"
else:
print "All globals() printed\n"
print "Globals (Generator):"
try:
print "\n".join("\t%s" % i for i in globals())
except RuntimeError:
print "Only some globals() printed\n"
else:
print "All globals() printed\n"
Why is it with a generator I get everything out but with a for loop I
don't? I know that globals is not read-only but I would of expected
the same behaviour from both...
Any thoughts?
print "Globals (For Loop):"
try:
for i in globals():
print "\t%s" % i
except RuntimeError:
print "Only some globals() printed\n"
else:
print "All globals() printed\n"
print "Globals (Generator):"
try:
print "\n".join("\t%s" % i for i in globals())
except RuntimeError:
print "Only some globals() printed\n"
else:
print "All globals() printed\n"
Why is it with a generator I get everything out but with a for loop I
don't? I know that globals is not read-only but I would of expected
the same behaviour from both...
Any thoughts?