python - 创建一个在调用另一个类函数时调用的类函数 Python
问题描述
我想要一个包含一个函数的类,每当调用另一个类函数时都会调用该函数。棘手的部分是我希望它适用于派生类。
比方说:
def class A:
def __init__(self):
pass
def b(self):
print("Hello")
和
def class B(A):
def __special_method__(self):
print("Before Hello")
调用 object.b() 会打印
Before Hello
Hello
这甚至可能吗?
解决方案
推荐阅读
- .net - 将图像发送到 Web API
- inheritance - “公共只读”访问修饰符?
- c# - 使用字符串插值将字符串转换为大写
- angular - 数组在函数内部获取搜索结果的值,但似乎没有保留它
- matlab - 计数满足条件的值
- sql - 我想确保 Microsoft SQL 表中的每一行都是唯一的
- javascript - 如何访问 localStorage 中的特定元素?
- react-native - 在手风琴组件中,我只想给表头 1 次
- r - 根据前几行替换几行的值
- google-cloud-kms - 使用 Python 从 KMS 解密文件失败,出现错误“400 Decryption failed: the ciphertext is invalid”