擅长:python、mysql、java
<p>您的用户可能会发现API行为令人困惑。然而,如果你确定你需要这种模式,你可以尝试类似的方法</p>
<pre><code># getattr will get the function attribute by a string name version
# None is returned if no function is found
my_func = getattr(self, 'my_func', None)
# callable ensures `my_func` is actually a function and not a generic attribute
# Add your if-else logic here
if callable(my_func):
my_func(args)
else:
...
</code></pre>