Multiple arguments: how do you handle them 'nicely'?

Erik Max Francis max at alcyone.com
Fri Aug 9 07:52:38 CEST 2002


Erik Max Francis wrote:

> Why not something like:
> 
>         def f(*args):
>             if len(args) == 1:
>                 args = args[0]

Err, that's obviously wrong.  I obviously meant

	      if len(args) == 1 and \
                 type(args[0]) in (types.ListType, types.TupleType):
	           ...

Although obviously that doesn't take into account arbitrary sequences. 
In that case a reasonable test might be to try to do len(args[0]), catch
the error if it's not a sequence type, and go from there.

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE
/  \ There is nothing so subject to the inconstancy of fortune as war.
\__/ Miguel de Cervantes
    Church / http://www.alcyone.com/pyos/church/
 A lambda calculus explorer in Python.



More information about the Python-list mailing list