我有4个类,其中3个是彼此继承的。由类D的对象d调用的方法'f'。如何找到属于类D的对象的方法'f'?
我在模块检查中进行了搜索,但是对于像我这样的初学者来说确实很混乱。
DataTable(
columns: <DataColumn>[
DataColumn(
numeric: true,
label: Container(
child: Text(
"ID", style: TextStyle(fontSize: 16, color: Colors.white)),
alignment: Alignment.center,
width: 50,
height: 30,
decoration: BoxDecoration(
border: Border.all(), color: Colors.lightBlue)),
tooltip: "ID OF THE NAME")
],
rows:[
DataRow(cells: <DataCell>[
DataCell(
Row(children: <Widget>[
Expanded(child: Dismissible(
child: ListTile(
title: Text(data)),
key: ObjectKey(value++),
onDismissed: (direction){
setState(() {
_add.remove(data);
});
},
))
]),
)
])
]
);
答案 0 :(得分:1)
此附加的打印语句将执行以下操作:
class A:
def f(self, a, b):
print(f"f called from an instance of {self.__class__.__name__}")
# or:
# print(f"f called from an instance of {type(self)}")
return a + b
以您为例,它将打印:
f called from an instance of D