python trying to pass list in as variable in function TypeError: 'int' object is not iterable -


i'm trying pass list in variable (var1) keep getting typeerror: 'int' object not iterable. added list comprehension thinking need make iterate in order sum. didn't work, i'm not sure type error means if doesn't mean need iterate on list var1. splat works, converts tuple list sums list. won't work given list var1.

    class mathdojo(object):         def __init__(self):             self.count = 0          def add(self,var1,*args):             self.var1 = var1             self.var1 = [x x in self.var1, sum(self.var1)]             self.args = list(args)             self.args = sum(self.args)             self.count += (self.var1 + self.args)             return self           def subtract(self,var1,*args):             self.var1 = var1             self.var1 = sum(self.var1)             self.args = list(args)             self.args = sum(self.args)             self.count += -(self.var1 + self.args)             return self          def result(self):             print self.count             return self      test = mathdojo()     test.add(2,2,2).subtract([3,2,1],3,1,2).add(1,3,5,6,7).subtract(3,4,6).result()       traceback (most recent call last):       file "mathdojo.py", line 26, in <module>         test.add(2,2,2).subtract([3,2,1],3,1,2).add(1,3,5,6,7).subtract(3,4,6).result()       file "mathdojo.py", line 6, in add         self.var1 = [x x in var1, sum(var1)]     typeerror: 'int' object not iterable 

test.add(2,2,2) make var1 equal 2. 2 not list, line x x in self.var1, sum(self.var1) have error, because both , sum requires list , 2 integer. can use test.add([2,2,2])


Comments