相关疑难解决方法(0)

安装程序中单元测试函数的Python打印名称

看完后 如何在Python中以字符串形式获取函数名称?

我想知道是否有可能将日志记录语句放入其中之一

def setUp(self):
    ... 

def tearDown(self):
    ...
Run Code Online (Sandbox Code Playgroud)

并打印当前测试功能的名称。

python unit-testing

2
推荐指数
1
解决办法
1260
查看次数

在函数本身中打印函数名称

我有很多功能,例如:

def DBworker_thatdoes_job7():
    print "DBworker_thatdoes_job7 starting..."

    ... the actual code here ...

    print "DBworker_thatdoes_job7 finished."
Run Code Online (Sandbox Code Playgroud)

如何在不硬编码函数名称的情况下执行此操作?这是我想要实现的目标:

def DBworker_thatdoes_job7():
    print thisfunction.name + " starting..."
    ...

def DBworker_thatdoes_cleaning18():
    print thisfunction.name + " starting..."
    ...
Run Code Online (Sandbox Code Playgroud)

注意:我已经看过如何在 Python 中将函数名作为字符串获取?但我真的没有看到在这里做这件事的好方法。此外,这个问题接近于在该函数内确定函数名称(不使用回溯),但这里适用于启动和结束时函数名日志记录的特定用例,因此不完全是重复的。

python function

2
推荐指数
1
解决办法
333
查看次数

在python中返回函数名?

做一个类型的数学函数def.

def integral_error(integral,f):
    ------stufff-------
    print integral
Run Code Online (Sandbox Code Playgroud)

给出类似的东西: '<function simpsons at 0xb7370a74>'

有没有办法让辛普森一家没有字符串操作?即只是功能名称?

python function

0
推荐指数
1
解决办法
811
查看次数

如何获取python定义的名称

有可能在python 2.7.3中获得这样一个定义的名称:

def Newname(self):
    print name_of_def

> "Newname"
Run Code Online (Sandbox Code Playgroud)

谢谢,

PUX

python function predefined-variables

0
推荐指数
1
解决办法
62
查看次数