在python中返回函数名? [英] Return function name in python?

查看:619
本文介绍了在python中返回函数名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

执行类型为 def 的数学函数。

Doing a math function of the type def.

def integral_error(integral,f):
    ------stufff-------
    print integral

给出类似于:'<函数辛普森在0xb7370a74>'

有没有一种方法可以让辛普森不用字符串操作?即只是函数名?

is there a way to get just simpsons without string manipulations? ie just the function name?

推荐答案

您可以使用:

integral.func_name

或者:

Or:

integral.__name__

虽然,它们完全相同。根据文档

Though, they are exactly equivalent. According to docs:


__ name __ 是另一种拼写方式func_name

__name__ is Another way of spelling func_name

以下是一个示例代码:

>>> def f():
    pass

>>> f.__name__
'f'
>>> f.func_name
'f'
>>> 

这篇关于在python中返回函数名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆