On Mon, Nov 14, 2016 at 3:54 PM, Steven D'Aprano
<steve+comp.lang.pyt...@pearwood.info> wrote:
>> Any particular reason to write it that way, rather than:
>>
>> def isiterable(obj):
>>     try:
>>         iter(obj)
>>         return True
>>     except TypeError:
>>         return False
>
>
> class BadIterable:
>     def __iter__(self):
>         self.launch_missiles()
>         return self
>
>
> In general, merely testing whether something is a certain kind of thing
> shouldn't actually run that thing's code.

True, but ISTR there being a possibility that __iter__ could raise to
indicate that this isn't actually iterable. Maybe I'm recalling wrong.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to