From a discussion with Martijn Pieters at stackoverflow
This is meant as a comment, posted as an answer because it is too big for the comment system. Answering to Martijn Pieters:
PauloScardine: but now you are inserting a value lookup each iteration. That's not more efficient. And in this specific case, you'd have to call
vars(MyClass)too, or do an extra attribute lookup withMyClass.__dict__
Probably the difference is marginal, but it is always good to profile before claiming some code is more efficient than other, so here we go:
$ python --version
Python 2.7.6