【发布时间】:2021-08-31 04:17:03
【问题描述】:
我有课
class A:
def __init__(self):
print(i was used by :)
# if i call this class from the function below,
def my_func():
a = A()
# I need class A to print that "i was used in: my_func() "
有什么解决办法吗?
【问题讨论】:
-
最好将打印内容放在
my_func中作为print("my_func willl now be calling A")。或者,只需将函数名称作为A("my_func")传递给A 的构造函数并使用它。 -
我的意思是,也许是通过使用各种堆栈自省技巧。几乎可以肯定,您应该只要求将函数作为参数提供。
-
@NielGodfreyPonciano 我不知道哪个函数正在调用我的类。我需要弄清楚哪些功能可以。在我的代码中某处,一个类被我找不到的函数使用。
标签: python python-2.7