Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are you allowed to modify func_defaults (__defaults__ in Python 3.x) in Python?

Tags:

python

I've tried doing this in Python 2.6, and it does "work":

>>> def f(i='I'): return i
...
>>> f.func_defaults = (10,)
>>> f()
10

But is this officially specified behavior, or am I hitting an implementation-specific behavior?

like image 455
allyourcode Avatar asked Dec 09 '12 05:12

allyourcode


1 Answers

In the documentation func_defaults is documented as "writable", so it would seem to be defined behavior.

like image 146
BrenBarn Avatar answered Oct 15 '22 07:10

BrenBarn