Author r.david.murray
Recipients Zero, docs@python, r.david.murray, terry.reedy
Date 2013-08-01.23:29:18
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1375399758.79.0.488038477513.issue18558@psf.upfronthosting.co.za>
In-reply-to
Content
“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 :)
History
Date User Action Args
2013-08-01 23:29:18r.david.murraysetrecipients: + r.david.murray, terry.reedy, Zero, docs@python
2013-08-01 23:29:18r.david.murraysetmessageid: <1375399758.79.0.488038477513.issue18558@psf.upfronthosting.co.za>
2013-08-01 23:29:18r.david.murraylinkissue18558 messages
2013-08-01 23:29:18r.david.murraycreate