Implicit lists

Mike Meyer mwm at mired.org
Thu Jan 30 11:30:32 EST 2003


Alex Martelli <aleax at aleax.it> writes:

> def iteron(something):
>     # string-like objects: treat as non-sequences
>     try: something+''
>     except TypeError: pass
>     else:
>         yield something
>         return
>     # other sequences
>     try:
>         for x in something: yield x
>     except TypeError:
>         yield something

I always thought that exceptions were expensive. Which makes me wonder
why you aren't using "isinstance(something, str)" for that first test.

        Thanks,
        <mike
-- 
Mike Meyer <mwm at mired.org>			http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.




More information about the Python-list mailing list