Python Forum
plistlib / xml file / get value except key
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
plistlib / xml file / get value except key
#4
You must understand the structure. Simple test:

import plistlib as pl

with open('Bookmarks_example.xml', 'rb') as f:
    data = pl.load(f)

for i, (key, value) in enumerate(data.items(), start=1):
    print(f'{i}. Key: {key}, value type: {type(value)}')
Which will display:

Output:
1. Key: Children, value type: <class 'list'>
So there is one key which has value of list type. Lets look what types does this list contains:

for i, item in enumerate(data['Children'], start=1):
    print(f'{i}.{type(item)}')
Output:
1.<class 'dict'> 2.<class 'dict'>
So there are two dictionaries in this list. What keys does these dictionaries have:

for i in range(2):
    print(f'{", ".join(data["Children"][i].keys())}')
Output:
Title, WebBookmarkIdentifier, WebBookmarkType, WebBookmarkUUID Children, Sync, Title, WebBookmarkFileVersion, WebBookmarkType, WebBookmarkUUID
...and so on.

Of course, one can print data outright and try to understand the structure :-).
Tecuma likes this post
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Messages In This Thread
RE: plistlib / xml file / get value except key - by perfringo - May-26-2021, 12:57 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Accessing nested dictionary values. Plistlib, Python 2.7 williamlombard 32 21,233 Sep-29-2017, 06:46 AM
Last Post: williamlombard

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020