Why the “mutable default argument fix” syntax is so ugly, asks python newbie

前端 未结 8 653
悲&欢浪女
悲&欢浪女 2020-11-30 09:00

Now following my series of \"python newbie questions\" and based on another question.

Prerogative

Go to http://python.net/~goodger/projects/pyco

8条回答
  •  旧巷少年郎
    2020-11-30 09:28

    Default arguments are evaluated at the time the def statement is executed, which is the probably the most reasonable approach: it is often what is wanted. If it wasn't the case, it could cause confusing results when the environment changes a little.

    Differentiating with a magic local method or something like that is far from ideal. Python tries to make things pretty plain and there is no obvious, clear replacement for the current boilerplate that doesn't resort to messing with the rather consistent semantics Python currently has.

提交回复
热议问题