Saturday, 10 August 2013

Counting how many specific items exist in a YAML file with Python

Counting how many specific items exist in a YAML file with Python

I'm attempting to find out how many "usernames" exist. Currently there are
2, and I can loop over users to get this, but that feels clunky. Is there
a way to get how many usernames exist in user?
open('c.yaml', 'r') as f:
c = yaml.safe_load(f)
# count number of usernames in user...?
c.yaml:
host: "example.com"
timeout: 60
work:
-
processes: 1
users:
-
username: "me"
-
username: "notme"

No comments:

Post a Comment