[Tutor] Check Number of Parameters Passed In

Kent Johnson kent37 at tds.net
Mon Jul 14 01:48:56 CEST 2008

On Sun, Jul 13, 2008 at 7:27 PM, James <jtp at nc.rr.com> wrote:
> Hi All,
> I'm writing a function that has optional paramters (i.e., "foo(
> parameter , optionalParameter = None , optionalParameter2 = None )").
> Is there some way inside of foo() that I can check to see how many
> parameters have been passed in? I want to check to ensure that only
> *one* optional parameter is passed in (and if more than one is passed
> in, do some sort of error handling).

Inside foo(), the optionalParameters will always be defined. Just
check if they are both None:

if optionalParameter is not None and optionalParameter2 is not None:
  print "Error, only one optional parameter can be provided."


More information about the Tutor mailing list