>> > 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 particular situation: adder() can be written so it > doesn't raise an exception on empty input. Brian gave a hint about this > when he asked: what happens if we try to sum up an empty sequence?
That's why I said I'd use the exception internally but return None from within the exception handler. I just think that catching the exception is the natural way to process the case of an empty input. Certainly cleaner than putting special processing in the main code body. (The real problem here is to figure out what exactly an adder should do when given nothing to add...) But maybe that's just me... Alan G. _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor