471,350 Members | 1,663 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,350 software developers and data experts.

Accessing function in a module by name

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

--
Posted via a free Usenet account from http://www.teranews.com

Jun 6 '07 #1
4 1110
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 ?
Jun 6 '07 #2
On Jun 7, 8:13 am, Tobiah <t...@tobiah.orgwrote:
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)
>
#Now call it
real_func(args)
Jun 6 '07 #3
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
--
Posted via a free Usenet account from http://www.teranews.com

Jun 6 '07 #4
Tobiah wrote:
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
Jun 7 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Tonguç Yumruk | last post: by
2 posts views Thread by Martin Drautzburg | last post: by
6 posts views Thread by garyjefferson123 | last post: by
14 posts views Thread by James Thiele | last post: by
3 posts views Thread by Mitko Haralanov | last post: by
5 posts views Thread by eliben | last post: by
10 posts views Thread by Chris | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.