Le Thursday 26 June 2008 16:41:27 [EMAIL PROTECTED], vous avez écrit :
> Hello. I am a novice programmer and have a question
>
> I have a configuration file(configuration.cfg)
> I read this from reading.py using ConfigParser
> When I use ConfigParser.get() function, it returns a string.
> I want to call a function that has the same name as the string from
> the configuration file.
>
>
You can find the function in the global dictionary (returned by globals()):
globs = globals()
func_name = config.read('1234', 'function')
func = globs[func_name]
# and then call it
func()
But a safer way would be to use a class with some static methods:
class Functions (object) :
@staticmethod
def efgh () :
blah blah...
and then find the function in the class dict:
func = getattr(Functions, func_name)
func()
this way you can restrict the set of functions the user can give, excluding
those which are not supposed to be called this way.
--
Cédric Lucantis
--
http://mail.python.org/mailman/listinfo/python-list