ConfigParser: Can I read(ConfigParser.get()) a configuration file and use it to call a funciton?
jamitwidme at gmail.com
jamitwidme at gmail.com
Thu Jun 26 16:01:39 EDT 2008
Thank you for the answers.
Now I understood how to call a function, let me ask you another
question.
configuration.cfg
---------------------------------------
[1234]
title: abcd
function: efgh
---------------------------------------
reading.py
--------------------------------------------------------
import ConfigParser
class Functions:
def efgh(self):
print 'blah'
fcn = Functions()
config = ConfigParser.ConfigParser()
config.read('configuration.cfg')
title = config.get('1234','title') # number 1
function_name = config.get('1234','function')
title = getattr(fcn, function_name)
title()
--------------------------------------------------------
instead of assigning string value('abcd') to title at number 1
I want to assign this function(fcn.efgh()) to abcd and make abcd a
FunctionType.
so later on, I want to call it by abcd(), not title().
The reason is I will have a loop reading from configuration file, so I
need to have different names for each function.
abcd is a string I read got it from config.get('1234','title')
Thanks again.
More information about the Python-list
mailing list