default values of function parameters

Terry Reedy tjreedy at udel.edu
Mon Jun 6 00:22:12 EDT 2005


"David Isaac" <aisaac0 at verizon.net> wrote in message 
news:piPoe.8518$ld3.1868 at trnddc04...
> But the default values of function parameters seem rather like a static
> attributes of a class.
> Is that a good way to think of them?

If you think of a function as defining a subclass of execution instances, 
with __init__ inherited from the superclass, then that is a possible way to 
think of them.  Goodness depends on your meaning of goodness ;-).  Does it 
help you write and use Python functions acurately?

> If so, are they somehow accessible?
> How? Under what name?

This is implementation specific.  For CPython, the interactive interpreter 
is your friend.  Learn to use it!

>>> def f(): pass
...
>>> dir(f)
['__call__', '__class__', '__delattr__', '__dict__', '__doc__', '__get__', 
'__ge
tattribute__', '__hash__', '__init__', '__name__', '__new__', '__reduce__', 
'__r
epr__', '__setattr__', '__str__', 'func_closure', 'func_code', 
'func_defaults',
'func_dict', 'func_doc', 'func_globals', 'func_name']

Now give f some parameters with defaults and print f.func_defaults.

Terry J. Reedy






More information about the Python-list mailing list