Added snippet to test if an object is iterable.

This commit is contained in:
Donne Martin 2015-01-23 16:47:51 -05:00
parent a7262a50a2
commit 52552208c1
2 changed files with 13 additions and 2 deletions

View File

@ -1,5 +1,6 @@
from nose.tools import assert_equal
from nose.tools import raises
from pydatasnippets.util import Util
class TestUtil():
@ -35,5 +36,6 @@ class TestUtil():
def test_attributes_fail(self):
return getattr('foo', 'bar')
def test_is_iterable(self):
assert_equal(Util.is_iterable('foo'), True)
assert_equal(Util.is_iterable(7), False)

9
util.py Normal file
View File

@ -0,0 +1,9 @@
class Util:
@classmethod
def is_iterable(self, obj):
try:
iter(obj)
return True
except TypeError:
return False