【问题标题】:Is there a way to identify a functions name from within the function? [duplicate]有没有办法从函数中识别函数名称? [复制]
【发布时间】:2020-05-12 06:53:44
【问题描述】:

有没有办法从函数中找到函数名?

def some_function():
    function_name = ... # some way of retrieving the name 'some_function'
    print(function_name)

function_name 的预期值为字符串:'some_function'

【问题讨论】:

标签: python function


【解决方案1】:

some_function.__name__ 应该可以工作

【讨论】:

  • 在这种情况下,您也可以简单地使用'some_function'...
猜你喜欢
  • 1970-01-01
  • 2020-09-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-10-18
  • 2019-05-30
  • 2021-12-02
相关资源
最近更新 更多