Skip to content

Instantly share code, notes, and snippets.

@bencharb
Last active August 29, 2015 14:17
Show Gist options
  • Save bencharb/c830c3ee9b1f28e79534 to your computer and use it in GitHub Desktop.
Save bencharb/c830c3ee9b1f28e79534 to your computer and use it in GitHub Desktop.
is positive int
#!/usr/bin/python
def is_positive_int(thing):
try:
assert(unicode(thing).isdigit())
except Exception:
return False
else:
return True
def _test_is_positive_int():
try:
for val in 12, '12':
assert(is_positive_int(val) is True)
for val in '5.0', '-5.0', '-5', -5, True, False, lambda: None, NotImplemented:
assert(is_positive_int(val) is False)
except AssertionError:
print 'test failed'
import sys
exc_class, exc, tb = sys.exc_info()
raise exc_class, exc, tb
else:
print 'test succeeded'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment