瀏覽代碼

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