ken at seehart.com
Sun Apr 24 19:07:02 CEST 2011
On 4/24/2011 2:58 AM, Steven D'Aprano wrote:
> Consider this in Python 3.1:
>>>> def f(a=42):
> ... return a
>>>> f.__defaults__ = (23,)
> Is this an accident of implementation, or can I trust that changing
> function defaults in this fashion is guaranteed to work?
This is documented in python 3, so I would expect it to be stable (until
python 4, that is)
The f.__defaults__ attribute was previously known as f.func_defaults (in
python 2.x), which has been around, documented and stable for quite a while.
So it's probably just as safe as any other monkey patching technique. :)
Best of luck,
More information about the Python-list