python-2.1 function attributes

Mike Romberg romberg at smaug.fsl.noaa.gov
Wed Jan 24 17:35:57 EST 2001


>>>>> " " == Terry Reedy <tjreedy at udel.edu> writes:

[snip]

     > Not having read the PEP, I wondered 'what is this good for?'
     > when I read GvR's announcement.  The PEP gives three possible
     > uses.  Is your use something different?  (that you can tell
     > us?)

  We are developing software to assist weather forecasters in
generating gridded forecasts.  We use an embeded python interpreter to
allow them to define functions which relate various weather paramaters
to each other.  For example there is a simple rule which states that
the dewpoint should never be higher than the temperature.  So a simple
function could be entered:

def dewpointChecker(temperature, dewpoint):
    if dewpoint < temperature:
        return temperature
    return dewpoint

  We currently use the neat intospection features of python (the
co_argcount and co_varnames attributes) to find the names of the
arguments.  It is not so easy to provide a slick method to specify
what paramater this function applies to.  The function name could be
used.  But, we would like to have multiple functions per paramater.
Adding an attribute nicely solves this problem for us:

def dewpointChecker(temperature, dewpoint):
    # Sample attibute syntax
    { 'paramater' : 'dewpoint' }
    if dewpoint < temperature:
        return temperature
    return dewpoint

  Now an engine can be built which has a list of functions.  When some
paramater changes it can run each of the functions it needs to by
first looking at the 'paramater' attribute.  All functions which match
the paramater are run with the other arguments looked up by examining
the argument list.

  This is probably just about as clear as dirt :).  But the function
attributes really do make life easier for us.

Mike (romberg at fsl.noaa.gov)








More information about the Python-list mailing list