Multiple arguments: how do you handle them 'nicely'?
op73418 at mail.telepac.pt
Fri Aug 9 14:08:16 CEST 2002
On Thu, 08 Aug 2002 22:52:38 -0700, Erik Max Francis <max at alcyone.com>
>Erik Max Francis wrote:
>> Why not something like:
>> def f(*args):
>> if len(args) == 1:
>> args = args
>Err, that's obviously wrong. I obviously meant
> if len(args) == 1 and \
> type(args) 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), 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.
With my best regards,
More information about the Python-list