I use configparser to get values for my python script, but I need to call function stored in config.ini... Since all values in configparser are stored as strings, is it possible to transform string into syntax? If so, how?
1 Answer
You can try using eval, documentation here.
Or you can try exec, documentation here.
By be careful, these are just quick and dirty way.
A better and much more safer method is to use getattr() (documentation) and setattr() (documentation) which indexes into globals.
1 Comment
Blender
@Mirac7:
ast.literal_eval is the safe way. It won't handle actual Python expressions like 'a' + 'b', but it will transform literal strings like [1, 2] and {'a': 'b'} into Python objects. eval() is easily exploitable.
execthe string, or I supposeevalif it is alambdaexpression ...