python - Finding if a plist contains a key with a specific string -
below have xml/plist file (you may recognize .tmtheme):
<?xml version="1.0" encoding="utf-8"?> <!doctype plist public "-//apple computer//dtd plist 1.0//en" "http://www.apple.com/dtds/propertylist-1.0.dtd"> <plist version="1.0"> <dict> <key>settings</key> <array> <dict> <key>name</key> <string>comment</string> <key>scope</key> <string>comment</string> <key>settings</key> <dict> <key>foreground</key> <string>#75715e</string> </dict> </dict> <dict> <key>name</key> <string>string</string> <key>scope</key> <string>string</string> <key>settings</key> <dict> <key>foreground</key> <string>#e6db74</string> </dict> </dict> </array> </dict> </plist>
i'm trying find if each dictionary contains string scope
, if scope
has specific string, comment
. need go inner dictionary , retrieve key foreground
. in case, need retrieve #75715e
.
i've started using a = plistlib.readplist()
b = a["settings"]
. i'm not sure how should approach it, keeping in mind need find root dictionary later on can other dictionary in it.
my_plist = plistlib.readplist() settings = my_plist["settings"] d in settings: if "scope" in d: if "comment" not in d["scope"]: print "a scope no comment!" else: print "a dict no scope!"
Comments
Post a Comment