Using both keyword=something and *unknownqty arguments in a function

David Eppstein eppstein at ics.uci.edu
Mon Dec 22 20:06:40 EST 2003


In article <vuf0da834iuc2a at corp.supernews.com>,
 "Francis Avila" <francisgavila at yahoo.com> wrote:

> >def skeptic(first='Zeus', second='Guido', *others)
> > print first
> > print second
> > print others
> > return "and I did not think it could ever work!"

I think there is not so much problem mixing keyword=something and 
*unknownqty, as long as you do not also allow named positional arguments.

def skeptic(*others, **keywords):
   print keywords['first']
   print keywords['second']
   print others
   return "and I did not think it could ever work!"

>>> answer=skeptic('believer', 'non-believer', 'heretic', first='Eric', 
second='unknown')
Eric
unknown
('believer', 'non-believer', 'heretic')
>>> answer
'and I did not think it could ever work!'

-- 
David Eppstein                      http://www.ics.uci.edu/~eppstein/
Univ. of California, Irvine, School of Information & Computer Science




More information about the Python-list mailing list