Implicit lists

Laura Creighton lac at strakt.com
Thu Jan 30 17:48:29 CET 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.
> -- 
> http://mail.python.org/mailman/listinfo/python-list

So when I pass it a string-like object I have made, the code just works.

Laura





More information about the Python-list mailing list