Function __defaults__

Benjamin Kaplan benjamin.kaplan at case.edu
Sun Apr 24 13:02:35 EDT 2011


On Sun, Apr 24, 2011 at 5:58 AM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> Consider this in Python 3.1:
>
>
>>>> def f(a=42):
> ...     return a
> ...
>>>> f()
> 42
>>>> f.__defaults__ = (23,)
>>>> f()
> 23
>
>
> Is this an accident of implementation, or can I trust that changing
> function defaults in this fashion is guaranteed to work?
>
>
>
> --
> Steven

Jython 2.5.1 (Release_2_5_1:6813, Sep 26 2009, 13:47:54)
[Java HotSpot(TM) 64-Bit Server VM (Apple Inc.)] on java1.6.0_24
Type "help", "copyright", "credits" or "license" for more information.
>>> def f(a=42) :
...    return a
...
>>> f()
42
>>> f.__defaults__ = (23,)
>>> f()
42

I'm going to go with implementation detail.

>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list