【发布时间】:2021-07-19 09:15:35
【问题描述】:
我试图找到一种方法来遍历对象列表并确定对象属于哪个类,一些对象属于父类,一些属于子类。 这就是我所期待的,但不知道如何让它发挥作用。
class example1():
def __init__(self,attribute1,attribute2,attribute3,etc):
self.attribute1 = attribute1
self.attribute2 = attribute2
*etc...*
class example2(example1):
def __init__(self,newAttribute1,newAttribute2,newAttribute3,etc):
self.newAttribute1 = newAttribute1
self.newAttribute2 = newAttribute2
*etc...*
*Code to create a list of a mix of both class example1 and example2*
for object in listOfObjects:
if object *belongs to* example1:
*do this*
else:
*do this instead*
【问题讨论】: