Danny Yoo said unto the world upon 2005-12-18 15:19:
>> > This is caused by the line: print adder(). Obviously
>> > if adder() doesn't receive any arguments, it can't
>> > build the lists resulting in an IndexError.
>>
>>Right.
>
>
> Hello!
>
> Just wanted to clarify the situation: argsList end
>> > line 3, in adder
>> >sum = argsList[0]
>> > IndexError: list index out of range
>> >
>> > an IndexError. What is the best way to solve this? Should I write
>> > some syntax into the function to check for arguments?
>>
>> The Pythonic way is to use exceptions.
>
> I disagree for this par
> > This is caused by the line: print adder(). Obviously
> > if adder() doesn't receive any arguments, it can't
> > build the lists resulting in an IndexError.
>
> Right.
Hello!
Just wanted to clarify the situation: argsList ends up being the empty
list, which is a perfectly good value:
On Sun, 18 Dec 2005, Alan Gauld wrote:
> > def adder(**args):
> >argsList = args.values()
> >sum = argsList[0]
> >for x in argsList[1:]:
> >sum = sum + x
> >return sum
>
> > line 3, in adder
> >sum = argsList[0]
> > IndexError: list index out of range
> >
> > This is
> def adder(**args):
>argsList = args.values()
>sum = argsList[0]
>for x in argsList[1:]:
>sum = sum + x
>return sum
> line 3, in adder
>sum = argsList[0]
> IndexError: list index out of range
>
> This is caused by the line: print adder(). Obviously
> if adder() doesn
Christopher Spears wrote:
> I got my function to work! It takes arguments and
> adds them:
>
> def adder(**args):
> argsList = args.values()
> sum = argsList[0]
> for x in argsList[1:]:
> sum = sum + x
> return sum
>
> print adder()
>
> However, if I run the above code.
Christopher Spears said unto the world upon 2005-12-18 01:30:
> I got my function to work! It takes arguments and
> adds them:
Hi Christopher,
great!
> def adder(**args):
> argsList = args.values()
> sum = argsList[0]
> for x in argsList[1:]:
> sum = sum + x
> r
I got my function to work! It takes arguments and
adds them:
def adder(**args):
argsList = args.values()
sum = argsList[0]
for x in argsList[1:]:
sum = sum + x
return sum
print adder()
print "---"
print adder(a=5)
print "---"
print adder(a=5,b=6)
print "---"
print adder(a