I have a dropdown box where the user can select a method to check whether a certain string either equals or endswith another string.
I would think to use function pointers/objects as the dropdown box model and call the one currently selected, but since the methods are/would be
- string methods and
- equals doesn’t exist
how do you best approach this in Python, also given that I’d have to call the methods on the column name like column.name.[selectedMethod](variableStringFromTextBox)?
(It’s an option that on a GUI reads “Use XYZ where column name [equals or endswith] ” + textbox with variable string.)
Thanks
If I understand you correctly, the dropdown list contains strings. An easy way to do it is define the appropriate methods, then use
globals(). For example:Suppose the strings are A and B and the string holding the function name is S. Then
Will invoke the function on A and B
globals()is a dictionary holding all global functions you defined, mapping from method names to method objects.You can also maintain a dictionary of your own that maps from method names to the methods objects.