timgeb, :
, int, :
class intlist(object):
def __init__(self, lst = []):
not_int_list = filter(lambda x: not isinstance(x, int), lst)
if not_int_list:
if len(not_int_list) > 1:
items = ', '.join(not_int_list)
raise NonIntError(items + ' are not int type')
item = not_int_list.pop()
raise NonIntError(item + ' is not int type')
il = intlist([1,2,3,'apple']), :
>>> NonIntError: apple is not int type
il = intlist([1,2,3,'apple','banana']), :
>>> NonIntError: apple, banana are not int type
, , int, .
:
not_int_list = filter(lambda x: not isinstance(x, int), lst)
filter isinstance .
if len(not_int_list) > 1:
items = ', '.join(not_int_list)
raise NonIntError(items + ' are not int type')
item = not_int_list.pop()
raise NonIntError(item + ' is not int type')
, .
NonIntError(items + ' are not int type')
timgeb. .