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

Gonçalo Rodrigues op73418 at
Fri Aug 9 14:08:16 CEST 2002

On Thu, 08 Aug 2002 22:52:38 -0700, Erik Max Francis <max at>

>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.

Even better, after

if len(args) == 1

use  a try/except block to see if you are passed an iterable, e.g.

    it = iter(args)
#Not an iterable - proceed acordingly.
except TypeError:

With my best regards,
Gonçalo Rodrigues

More information about the Python-list mailing list