Use `__dict__` or `vars()`?

前端 未结 3 1248
忘了有多久
忘了有多久 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:57

    I'd use vars().

    From: https://wiki.python.org/moin/DubiousPython#Premature_Optimization

    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

    Readability counts.

提交回复
热议问题