如何訪問對象中的實例並將其傳遞給另一個「主」對象?我正在使用解析器解析不同標記的文件,INDI(個人),BIRT(事件),FAMS(配偶),FAMC(子女)從另一個類訪問類變量
基本上有三個類:Person,Event,Family
class Person():
def __init__(self, ref):
self._id = ref
self._birth : None
def addBirth(self, event):
self._birth: event
class Event():
def __init__(self, ref):
self._id = ref
self._event = None
def addEvent(self, event):
self._event = event
#**event = ['12 Jul 1997', 'Seattle, WA'] (this is generated from a function outside a class)
我想將self._vent從Event類轉移到addBirth方法中,將它添加到我的person類中。我對階級和階級聯合會如何工作知之甚少。請幫忙!
只需將一個參數添加到所需的方法並從適當的調用者傳遞它? – Tobias