1

以下に xml/plist ファイルがあります (.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>

scope各辞書に文字列が含まれているかどうか、およびscope特定の文字列が含まれているかどうかを調べようとしていますcomment。次に、内部辞書に移動してキーを取得する必要がありますforeground。この場合、取得する必要があります#75715E

私はa = plistlib.readPlist()thenを使って始めましたb = a["settings"]。次に、ルート辞書を後で見つける必要があることを念頭に置いて、どのようにアプローチすればよいかわかりません。これにより、他の辞書を取得できます。

4

1 に答える 1

1
my_plist = plistlib.readPlist()
settings = my_plist["settings"]
for d in settings:
    if "scope" in d:
        if "comment" not in d["scope"]:
            print "A scope with no comment!"
    else:
        print "A dict with no scope!"
于 2012-07-07T00:58:40.813 に答える