How to call Python functions dynamically
问题 I have this code: fields = ['name','email'] def clean_name(): pass def clean_email(): pass How can I call clean_name() and clean_email() dynamically? For example: for field in fields: clean_{field}() I used the curly brackets because it's how I used to do it in PHP but obviously doesn't work. How to do this with Python? 回答1: If don't want to use globals, vars and don't want make a separate module and/or class to encapsulate functions you want to call dynamically, you can call them as the