vars() looks more Pythonic to me, but I see
__dict__ used more frequently.
The Python documentation indicates that they are equivalent.
One blogger claims that
__dict__ is faster than
Which shall I use?
While a correctly applied optimization can indeed speed up code, optimizing code that is only seldom use [..] can make code harder to read. [..] Write correct code first, then make it fast (if necessary).
From: The Zen of Python
Generally, you should consider dunder/magic methods to be the implementation and invoking functions/methods as the API, so it would be preferable to use
__dict__, in the same way that you would do
len(a_list) and not
a_dict["key"] rather than
vars should be preferred. My rationale is that, as python evolves,
vars might be extended to do more than
__dict__ does (for example, work for objects with slots, possibly in 3.7).