17/04/2008

Messing with default values

How to change/set default values for a function ( I wouldn't actually encourage anyone to use this! ):

>>> def a(b, c):
...     print b, c
...
>>> a()
Traceback (most recent call last):
  File "", line 1, in 
TypeError: a() takes exactly 2 arguments (0 given)
>>> a.func_defaults = (1, 2)
>>> a()
1 2

No comments: