rendered paste body# Code snippet here:for user in userList: for phone in (str(user[5]), str(user[6])): try: phone = ''.join([c for c in phone if c.isdigit()]) if len(phone) == 4: # An extension? print "Len = 4" phone = "ext %s" % phone elif len(phone) == 7: # A local number? print "Len = 7" phone = '252-%s-%s' % (phone[0:3], phone[3:]) elif len(phone) == 10: # Area code + local? print "Len = 10" phone = '%s-%-%s' % (phone[0:3], phone[3:6], phone[6:]) elif len(phone) == 14: # Area code + local + extension print "Len = 14" phone = '%s-%-%s ext%s' % (phone[0:2], phone[3:5], phone[6:9], phone[10:]) except IndexError, e: print "Exception: Got IndexError for %s" % phone print e sys.exit() except TypeError, e: print "Exception: Got TypeError for %s (%s)" % (phone, type(phone)) print e sys.exit() else: if len(phone) > 0: print "phone = %s" % phone# Output:# # [admin@paczilla] {~/dan} ./print_users.py# Len = 4# phone = ext 7324# Len = 7# phone = 252-567-8910# Len = 10# Exception: Got TypeError for 2345678910 (<type 'str'>)# not all arguments converted during string formatting## Raw traceback (if exception handling is disabled:## Traceback (most recent call last):# File "./print_users.py", line 51, in ?# phone = '%s-%-%s' % (phone[0:3], phone[3:6], phone[6:])# TypeError: not all arguments converted during string formatting