[portland] Using Dictionary to Call Functions
Rich Shepard
rshepard at appl-ecosys.com
Tue Jan 15 02:01:05 CET 2008
I've read in the Python Cookbook and various web sites the information on
using a dictionary as a switch statement would be used in C. But, I've not
seen -- or figured out -- how to call the keys correctly while passing
arguments to the called function. Let me explain.
The dictionary:
curvePlot = {
'Decay S-Curve' : functions.zCurve(leftEdge, rightEdge),
'Bell Curve' : functions.gaussCurve(midpt, width),
'Growth S-Curve' : functions.sCurve(leftEdge, rightEdge),
'Beta' : functions.betaCurve(center, inflectPt, width),
'Data' : functions.dataCurve(ptList),
'Linear Increasing' : functions.linearIncrCurve(leftEdge, rightEdge),
'Linear Decreasing' : functions.linearDecrCurve(leftEdge, rightEdge),
'Left Shoulder' : functions.leftShoulderCurve(hiRight, loRight),
'Trapezoid' : functions.trapezoidCurve(loLeft, hiLeft, hiRight, loRight),
'Right Shoulder' : functions.rightShoulderCurve(loLeft, hiLeft, hiRight),
'Triangle' : functions.triangleCurve(loLeft, center, loRight),
'Singleton' : functions.singletonCurve(center, width),
'Rectangle' : functions.rectangleCurve(leftEdge, rightEdge),
'Outcome' : functions.outcomeCurve()
}
For each tuple in the list (from a database table) there is a value
called 'shape.' This is the dictionary's key. The arguments are also values
in each tuple, and they differ for each function call.
I want to get the dictionary keys in sequential order (there may be 1 to
7), and call the appropriate function for each one. The functions use
mathplotlib to draw the curves on a common set of axes.
Suggestions and thoughts welcomed.
Rich
--
Richard B. Shepard, Ph.D. | Integrity Credibility
Applied Ecosystem Services, Inc. | Innovation
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863
More information about the Portland
mailing list