Testing for presence of arguments

Benji York benji at benjiyork.com
Wed Aug 17 11:50:05 EDT 2005


Madhusudan Singh wrote:
> I know how to set optional arguments in the function definition. Is there an
> intrinsic function that determines if a certain argument was actually
> passed ? Like the fortran 95 present() logical intrinsic ?

People generally use a value that isn't a valid option, often None.

def my_func(a, b, c=None):
     if c is None:
         do something

If None is a valid value, make one that isn't:

unspecified = object()

def my_func(a, b, c=unspecified):
     if c is unspecified:
         do something
--
Benji York




More information about the Python-list mailing list