Use `__dict__` or `vars()`?

前端 未结 3 1254
忘了有多久
忘了有多久 2020-12-01 07:33

Builtin function vars() looks more Pythonic to me, but I see __dict__ used more frequently.

The Python documentation indicates that they ar

3条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-01 07:52

    I agree 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).

提交回复
热议问题