In python, it is easy.

>>> def foobar(): print 'hello world'
...
>>> exec('foobar'+'()')
hello world
>>>

However, the exec() might be considered dangerous if you are not sure
what function name string would be inside DB. So if I were you, I
would still use a translation system, but a more elegant one (I
think):

def foo(): print 'foo'
def bar(): print 'bar'
dispatcher={
  'foo': foo,
  'bar': bar,
}
def oops(): print "oops, I don't know that name"

dispatcher.get(func_name_str, oops) ()


On Sep19, 3:26pm, Jason Brower <encomp...@gmail.com> wrote:
> I think I have reached the limit of my python knowledge and need help.
> I have a table that holds "solutions" and the "issues" they solve.
> To find out what solutions is viable in difference cases I need to do a
> complicated set of checks.  I have placed these checks in a set of
> methods.
> Is there a way to reference these methods in the database?
> I was thinking something like this...
> We get the name from the table.
> method = "foobar"
> then I have a method called foobar
>
> def foobar():
>     return True
>
> How would I do that?
> Currently I have to make a translation system... if method = "foobar":
> foobar()
> But I am sure there is a better way.
> Regards,
> Jason
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to