Created
April 22, 2015 10:31
-
-
Save gjbagrowski/eddbdd0afd1c475d0975 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def is_enumerable(collection): | |
"""Checks if the variable is not a basestring instance and can be | |
enumerated. | |
""" | |
try: | |
# strings can be iterated - that's not what we want | |
if isinstance(collection, basestring): | |
return False | |
# avoid opening a generator | |
if isinstance(collection, types.GeneratorType): | |
return True | |
for a in collection: | |
break | |
return True | |
except TypeError: | |
return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment