I am bored, so am trying to get my head around yaml. When I import I get:
[{'plasma': [{'program': '/usr/bin/albert', 'params': '', 'runonce': 'T'}, {'program': '/usr/bin/firefox-nightly', 'params': '', 'runonce': 'T'}]}, {'gnome': [{'program': '/usr/bin/variety', 'params': 'This is a test!', 'runonce': 'T'}]}]
In a variable called read_data.
How the hell do I access the elements? Going around in circles
What I have so far:
#!/usr/bin/env python
# Import YAML module
import yaml
# Load the YAML file
with open('config.yaml') as fh:
# Load YAML data from the file
read_data = yaml.load(fh, Loader=yaml.FullLoader)
# Iterate the loop to read and print YAML data
for i in range(0, len(read_data)):
for key, value in read_data[i].items():
print(key, ":", value)
print('')
print(read_data)
The data:
# autostart config file
- plasma:
- program: "/usr/bin/albert"
params: ""
runonce: "T"
- program: "/usr/bin/firefox-nightly"
params: ""
runonce: "T"
- gnome:
- program: "/usr/bin/variety"
params: "This is a test!"
runonce: "T"