function taking scalar or list argument
Terry Reedy
tjreedy at udel.edu
Tue Aug 24 01:45:48 EDT 2004
"Steven Bethard" <steven.bethard at gmail.com> wrote in message
news:loom.20040824T052140-517 at post.gmane.org...
> Well, you can always test for the protocol, e.g.:
>
> def twice(x):
> if hasattr(x, "__iter__"):
> return map(twice, x)
In 2.2.1:
>>> hasattr([1,2,3], '__iter__')
0
so this does not seem to work as you seem to expect. hasattr(iter(x),
'__iter__') will.
Terry J. Reedy
More information about the Python-list
mailing list