By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,621 Members | 1,074 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,621 IT Pros & Developers. It's quick & easy.

Accessing function in a module by name

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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.