On Jun 26, 7:41 am, [EMAIL PROTECTED] wrote: > 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. > > configuration.cfg > --------------------------------------- > [1234] > title: abcd > function: efgh > --------------------------------------- > > reading.py > -------------------------------------------------------- > import ConfigParser > > def efgh(): > print 'blah' > > config = ConfigParser.ConfigParser() > config.read('configuration.cfg') > > fcn = config.get('1234','function') > type(fcn) > print fcn > -------------------------------------------------------- > > <type 'str'> > efgh > > Is there any way to call efgh() ? > One way I know is using if statement > if fcn == 'efgh': > efgh() > > But I am going to have many functions to call, so I want to avoid > this. > > Thank you for your help
Something like this: globals()[fcn]() -- http://mail.python.org/mailman/listinfo/python-list