We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 8d0e81f commit 66526e3Copy full SHA for 66526e3
docs/iterator.rst
@@ -44,4 +44,28 @@ a generator::
44
1
45
4
46
47
+
48
+`how do I determine if an object is iterable`_
49
+----------------------------------------------
50
51
+Duck typing::
52
53
+ try:
54
+ iterator = iter(theElement)
55
+ except TypeError:
56
+ # not iterable
57
+ else:
58
+ # iterable
59
60
+Type checking, need at least Python 2.6 and work only for new-style classes::
61
62
+ import collections
63
64
+ if isinstance(theElement, collections.Iterable):
65
66
67
68
69
70
.. _iterator - The Python yield keyword explained: http://stackoverflow.com/questions/231767/the-python-yield-keyword-explained
71
+.. _how do I determine if an object is iterable: http://stackoverflow.com/questions/1952464/in-python-how-do-i-determine-if-an-object-is-iterable
0 commit comments