I feel that there must be something simple, I am absent here. Here is what I want to do:
>>> def x(*args, a=False):
... print args, a
>>> x(1,2)
(1,2) False
>>> x(1,2,3, a=True)
(1,2,3) True
But you cannot define such a function.
I know this will work, but it doesn't look so nice:
>>> def x(*args, **kwargs):
... if 'a' in kwargs:
... a = kwargs['a']
... else
... a = False
... print args, a
What is the best way to do this?
I am using python 2.6
source
share