is parameter an iterable?

Roy Smith roy at panix.com
Tue Nov 15 21:59:44 EST 2005


In article <437A9596.6020006 at REMOVEMEcyber.com.au>,
 Steven D'Aprano <steve at REMOVEMEcyber.com.au> wrote:

> try:
>      for item in obj:
>          do_stuff(item)
> except TypeError, msg:
>      if msg == "iteration over non-sequence":
>          handle_non_iterator()
>      else:
>          # re-raise the exception
>          raise

That's the obvious solution, but it's a poor one because it depends on an 
undocumented feature of the language.  What's documented is that TypeError 
is raised; it's not documented what the text of the message will be.



More information about the Python-list mailing list