So I have a YML file, and I'm trying to convert it to a different format. I found a YML format converter script and edited it to the best of my ability, and this is what I've come up with:
#!/bin/python try: import yaml except: print "Failed to import module: yaml" f = open("config.yml") fh = f.read() f.close() orig_dict = yaml.load(fh) users = orig_dict['users'] space = " " print "users:" for user in users: print space + user + ":" for category in users[user]: if category == "groups": print space * 2 + "group:" for category_groups in users[user][category]: print space * 2 + "- " + category_groups else: print space * 2 + "ERROR"
It works, but the one problem is that I don't want to include users in the group "default" in the converted file. I've tried several things such as if category_groups != "default": print space * 2 + "- " + category_groups but that only omits the group, not the entire user. Is there a way to either skip users in the default group while printing the file or remove them after the file is printed? Help is appreciated :)