[docs] [issue18558] Iterable glossary entry needs clarification

R. David Murray report at bugs.python.org
Fri Aug 2 01:29:18 CEST 2013

R. David Murray added the comment:

“What is the proper way of asking if an object is iterable if it does not support the iterator protocol but does support the old getitem protocol?”

The *only* answer to that question is to try to iterate it, and see if you get a KeyError on "0".  Since this results in obtaining the first element if it *is* iterable, and in the general case you cannot "reset" an iterable, there is no way to look before you leap.  You have to catch the error after it occurs.

This question and answer probably do belong on Stack Overflow or python-list, but the glossary entry still needs improvement, since the Iterable docs reference it :)


Python tracker <report at bugs.python.org>

More information about the docs mailing list