如果我的术语不正确,我深表歉意。我正在尝试从 API 返回中获取函数的名称。例如,以下是从 API 返回的内容。如何获取名称 the_function
?
my_variable = <Function the_function(str,int,uint)>
上面的类型
是:
type(my_variable) = <class 'the_class.utils.datatypes.the_function'>
如果我只能访问我所显示的内容,如何获取文本字符串the_function
?除了将其转换为字符串并使用正则表达式或类似的东西之外,还有其他简单的方法吗?
最佳答案
如果您可以通过任何变量访问该函数,则可以使用 .__name__
:
>>> def the_function():
... pass
...
>>> the_function.__name__
'the_function'
>>> foo = the_function
>>> foo.__name__
'the_function'
关于python - 如何解析类属性的名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54035511/