python - AttributeError: NoneType object has no attribute -
i, python novice, following error message when executing code have received author:
line 412, in add_family mother_birth_ref = mother.get_birth_ref() attributeerror: 'nonetype' object has no attribute 'get_birth_ref'
the relevant part of code must 1 here:
def write_child_stats(self): file = open("%s/intern/child-stats.txt" % self.dir_name, 'w') def add_family(family, marriage_event, divorce_event): father_handle = family.get_father_handle() mother_handle = family.get_mother_handle() father = self.database.get_person_from_handle(father_handle) father_birth_ref = father.get_birth_ref() father_birth = none if father_birth_ref: father_birth = self.database.get_event_from_handle(father_birth_ref.ref) mother = self.database.get_person_from_handle(mother_handle) mother_birth_ref = mother.get_birth_ref() mother_birth = none if mother_birth_ref: mother_birth = self.database.get_event_from_handle(mother_birth_ref.ref) children = [] child_refs = family.get_child_ref_list() child_handle in child_refs: child = self.database.get_person_from_handle(child_handle.ref) if child: child_birth_ref = child.get_birth_ref() if child_birth_ref: child_birth = self.database.get_event_from_handle(child_birth_ref.ref) children.append("%04d-%02d-%02d" % child_birth.get_date_object().get_ymd())
how can fix issue?
mother = self.database.get_person_from_handle(mother_handle)
this line returning none
. check get_person_from_handle
function.
alternatively, can add check :
mother = self.database.get_person_from_handle(mother_handle) mother_birth_ref = none mother_birth = none if mother: mother_birth_ref = mother.get_birth_ref() if mother_birth_ref: mother_birth = self.database.get_event_from_handle(mother_birth_ref.ref)
Comments
Post a Comment