python - how can I dynamically create a function with a name based on a string read in from a file?
问题 Let's say I have a file containing the string "unpredictable_words". I would like to read in this string and then define a function as follows: def test_unpredictable_words(self): do_important_stuff() I would then like to inject this function into a class definition so that this function can be called on any instances of this class. How can I accomplish this? I looked a bit at this answer - https://stackoverflow.com/a/8160676/1701170 - but I don't think it does what I want, exactly, or at