Accessing function in a module by name

T

Tobiah

Is there a way to call function in an imported
module having only the name?


func_name = 'doit'

real_func = foo.some_magic(func_name)

#Now call it
real_func(args)


I'm trying to set up a function dispatcher for a
SOAP server.

Thanks,

Tobiah
 
I

imho

Tobiah ha scritto:
Is there a way to call function in an imported
module having only the name?


func_name = 'doit'

real_func = foo.some_magic(func_name)

#Now call it
real_func(args)


I'm trying to set up a function dispatcher for a
SOAP server.

Thanks,

Tobiah

What's wrong with real_func = getattr(foo, func_name) ? Maybe I
misunderstood your question ?
 
J

John Machin

Is there a way to call function in an imported
module having only the name?

func_name = 'doit'

real_func = foo.some_magic(func_name)

Presuming 'foo' is the name of the module:

real_func = getattr(foo, func_name)
 
T

Tobiah

What's wrong with real_func = getattr(foo, func_name) ? Maybe I
misunderstood your question ?

Nothing, it just didn't exist in my mind until now.

Thanks
 
J

John Nagle

Tobiah said:
Is there a way to call function in an imported
module having only the name? ....
I'm trying to set up a function dispatcher for a
SOAP server.

Bad idea. This exposes all the functions of the
module to calls from the outside world. Big security hole.

In any case, SOAP servers should have a separate object for
each connection, or the thing will mess up if two requests
are made at the same time.

See

http://www.ibm.com/developerworks/library/ws-pyth5/

John Nagle
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,291
Messages
2,571,453
Members
48,137
Latest member
IndiraMcCo

Latest Threads

Top