How can I test if an argument is a sequence or a scalar?

sandravandale at yahoo.com sandravandale at yahoo.com
Tue Jan 10 18:18:22 EST 2006


I want to be able to pass a sequence (tuple, or list) of objects to a
function, or only one.

It's easy enough to do:

isinstance(var, (tuple, list))

But I would also like to accept generators. How can I do this?

Anything else is assumed to be a single value (my fault if I pass a
dict or something else to the function) and I make it into a tuple with
a single value (var, ) in order to simplify the algorithm (wasn't there
a special name for a one item tuple? Its been a while since I've
programmed in Python.)

Is there an easy way to do that?

Thanks,
-Sandra




More information about the Python-list mailing list