Преглед изворни кода

readme: added multiple yaml files import sample

Fabian Peter Hammerle пре 4 година
родитељ
комит
8c6abe3585
1 измењених фајлова са 29 додато и 0 уклоњено
  1. 29 0
      README.md

+ 29 - 0
README.md

@@ -36,6 +36,35 @@ Person(alice-mother, Carol Test, *1992-10-26)
 
 ```
 
+#### Multiple YAML Files
+
+```python
+>>> alice_yaml = '''
+... !person
+... identifier: alice
+... name: Alice Test
+... birth_date: 2019-12-23
+... mother: carol
+... '''
+>>> carol_yaml = '''
+... !person
+... identifier: carol
+... name: Carol Test 
+... birth_date: 1992-10-26
+... '''
+>>> collection = yamily.PersonCollection()
+>>> for person_yaml in [alice_yaml, carol_yaml]:
+...     person = yaml.load(person_yaml, Loader=yamily.yaml.Loader)
+...     collection.add_person(person)
+Person(alice, Alice Test, *2019-12-23)
+Person(carol, Carol Test, *1992-10-26)
+>>> collection['alice'].mother
+Person(carol, Carol Test, *1992-10-26)
+>>> collection['carol'] is collection['alice'].mother
+True
+
+```
+
 ### Export YAML
 
 ```python