Re: [Tutor] design advice for function

2005-12-19 Thread Brian van den Broek
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

Re: [Tutor] design advice for function

2005-12-18 Thread Alan Gauld
>> > 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

Re: [Tutor] design advice for function

2005-12-18 Thread Danny Yoo
> > 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:

Re: [Tutor] design advice for function

2005-12-18 Thread Danny Yoo
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

Re: [Tutor] design advice for function

2005-12-18 Thread Alan Gauld
> 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

Re: [Tutor] design advice for function

2005-12-18 Thread Kent Johnson
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.

Re: [Tutor] design advice for function

2005-12-18 Thread Brian van den Broek
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

[Tutor] design advice for function

2005-12-17 Thread Christopher Spears
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