|
@@ -80,17 +80,18 @@ class Person:
|
|
>>> p2.father = Person("father")
|
|
>>> p2.father = Person("father")
|
|
>>> str(p2)
|
|
>>> str(p2)
|
|
'unnamed (*1976-02-01)'
|
|
'unnamed (*1976-02-01)'
|
|
|
|
+
|
|
|
|
+ add attributes of p2 to p1:
|
|
>>> p1.merge(p2)
|
|
>>> p1.merge(p2)
|
|
>>> str(p1)
|
|
>>> str(p1)
|
|
'Max Mustermann (*1976-02-01)'
|
|
'Max Mustermann (*1976-02-01)'
|
|
>>> p1.mother, p1.father
|
|
>>> p1.mother, p1.father
|
|
(Person(mother), Person(father))
|
|
(Person(mother), Person(father))
|
|
|
|
+
|
|
|
|
+ p2 is unchanged:
|
|
|
|
+ >>> str(p2)
|
|
|
|
+ 'unnamed (*1976-02-01)'
|
|
"""
|
|
"""
|
|
- if person.name is not None:
|
|
|
|
- self.name = person.name
|
|
|
|
- if person.birth_date is not None:
|
|
|
|
- self.birth_date = person.birth_date
|
|
|
|
- if person.mother is not None:
|
|
|
|
- self.mother = person.mother
|
|
|
|
- if person.father is not None:
|
|
|
|
- self.father = person.father
|
|
|
|
|
|
+ for attr in ["name", "birth_date", "mother", "father"]:
|
|
|
|
+ if getattr(person, attr) is not None:
|
|
|
|
+ setattr(self, attr, getattr(person, attr))
|