Problem with getting an option value

Larry Bates larry.bates at
Tue Apr 10 17:24:17 CEST 2007

Lucas Malor wrote:
> Peter Otten wrote:
>> Lucas Malor wrote:
>>> The problem is options is an instance, so options."delete", for example,
>>> is wrong; I should pass options.delete . How can I do?
>> Use getattr():
> Thank you. Do you know also if I can do a similar operation with functions? I want to select with a string a certain get() function of ConfigParser:
> if   type == "int" :
>     funcname = "getint"
> elif type == "bool" :
>     funcname = "getboolean"
> etc.
> How can I invoke the funcion with its name in a string?
> PS: your answers had not arrived to my mail account. Is because I'm using a disposal address? Or simply it's because I'm not registered to the list?
> --------------------------------------
> Protect yourself from spam, 
> use

Use a dispatch dictionary:

dispatch={'int': getint,
          'bool': getboolean}

then call it:


Note: You should NOT use type as a variable name because it will shadow
the built-in type function.


More information about the Python-list mailing list