473,396 Members | 2,013 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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 1178
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Tonguç Yumruk | last post by:
I'm trying to build a completely plug-in based system. One of my problems is importing a package dynamically. I'm trying to emulate the import command. The __import__() function or imp module...
2
by: Martin Drautzburg | last post by:
Withing a module I can assign a value to a global var by assigning to it in the outermost scope. Fine. But how can I do this if the attribute name itself is kept in a variable. Once the module...
6
by: garyjefferson123 | last post by:
I'm having a scoping problem. I have a module called SpecialFile, which defines: def open(fname, mode): return SpecialFile(fname, mode) class SpecialFile: def __init__(self, fname, mode):...
14
by: James Thiele | last post by:
I'd like to access the name of a function from inside the function. My first idea didn't work. >>> def foo(): .... print func_name .... >>> foo() Traceback (most recent call last): File...
1
by: Donald Grove | last post by:
I am suddenly getting this message. It happens during code executed from a form module that calls a function stored in a standard module. I am working on a standalone pc with no network connection...
13
by: Kirk | last post by:
I have been reading Scott Allen's article on Master Pages (http:// odetocode.com/Articles/450.aspx) but I am having problems understanding a concept. Specifically, I have created a property...
3
by: Mitko Haralanov | last post by:
I have a Python module that I have written using the C API and I am having a problem accessing a dictionary from that module. Here is what I have done: 1. In my init function I call module =...
5
by: eliben | last post by:
Hello, I have a game class, and the game has a state. Seeing that Python has no enumeration type, at first I used strings to represent states: "paused", "running", etc. But such a representation...
10
by: Chris | last post by:
Hi, I'd like to be able to access an attribute of a particular Python object as fast as possible from some C code. I wondered if using __slots__ to store the attribute would allow me to do...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.