Calling a function or method by name

Marc Poulin mpoulin at verinet.com
Mon Feb 4 14:40:16 EST 2002


In article <mailman.1011824379.21237.python-list at python.org>, "Jonathan
Gardner" <jgardn at alumni.washington.edu> wrote:

>>
> I remembered the real reason why. I want it to be modifiable with user
> input. This means eventually I'll have to convert a string to a
> function.
> 

This brings back some really bad memories. I once worked on a system that
consisted of a core run-time module that was customized through the use
of configuration tables stored in a relational database.

At start-up, the application would configure its internal function
dispatch tables by reading the *names* of the functions from the DB.

In my experience, this approach was quite brittle, since it was very easy
to misspell the name in the DB. Or sometimes a programmer would change the 
function name in the code without updating the corresponding entry in the DB.

My only advice is to think long and hard before you go down this path.



More information about the Python-list mailing list