trying yaml
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
# categories.yaml file
|
||||
|
||||
sports:
|
||||
|
||||
- soccer
|
||||
- football
|
||||
- basketball
|
||||
- cricket
|
||||
- hockey
|
||||
- table tennis
|
||||
|
||||
countries:
|
||||
|
||||
- Pakistan
|
||||
- USA
|
||||
- India
|
||||
- China
|
||||
- Germany
|
||||
- France
|
||||
- Spain
|
||||
@@ -0,0 +1,10 @@
|
||||
# fruits.yaml
|
||||
|
||||
apples: 20
|
||||
mangoes: 2
|
||||
bananas: 3
|
||||
grapes: 100
|
||||
pineapples: 1
|
||||
machin: 23
|
||||
truc: 21347
|
||||
last: 2q348789
|
||||
Executable
+27
@@ -0,0 +1,27 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import yaml
|
||||
|
||||
# Reading Yaml
|
||||
|
||||
with open('fruits.yaml') as file:
|
||||
fruits_dict = yaml.load(file, Loader=yaml.FullLoader)
|
||||
print(type(fruits_dict['last']))
|
||||
# print(fruits_dict)
|
||||
|
||||
# Note
|
||||
# yaml.load(file, Loader=yaml.FullLoader) = yaml.full_load(file)
|
||||
|
||||
# with open('categories.yaml') as file:
|
||||
# documents = yaml.full_load(file)
|
||||
# for item, doc in documents.items():
|
||||
# print(item, ":", doc)
|
||||
|
||||
# Writting Yaml
|
||||
# dict_file = [
|
||||
# {'sports' : ['soccer', 'football', 'basketball', 'cricket', 'hockey', 'table tennis']},
|
||||
# {'countries' : ['Pakistan', 'USA', 'India', 'China', 'Germany', 'France', 'Spain']}
|
||||
# ]
|
||||
|
||||
# with open("storing.yaml", 'w') as file:
|
||||
# documents = yaml.dump(dict_file, file)
|
||||
@@ -0,0 +1,15 @@
|
||||
- sports:
|
||||
- soccer
|
||||
- football
|
||||
- basketball
|
||||
- cricket
|
||||
- hockey
|
||||
- table tennis
|
||||
- countries:
|
||||
- Pakistan
|
||||
- USA
|
||||
- India
|
||||
- China
|
||||
- Germany
|
||||
- France
|
||||
- Spain
|
||||
Reference in New Issue
Block a user