Procházet zdrojové kódy

Guarantee stable output order

master
JustAnotherArchivist před 2 roky
rodič
revize
34503dd274
1 změnil soubory, kde provedl 5 přidání a 1 odebrání
  1. +5
    -1
      ia-files-xml-to-jsonl

+ 5
- 1
ia-files-xml-to-jsonl Zobrazit soubor

@@ -14,4 +14,8 @@ for file in root:
children = {child.tag: child.text for child in file}
assert not any(k in children for k in attributes), 'attribute found in children'
assert not any(k in attributes for k in children), 'child found in attributes'
print(json.dumps({**attributes, **children}))
assert 'name' in attributes, 'malformed file without name attribute'
o = {'name': attributes['name']}
del attributes['name']
o.update(sorted({**attributes, **children}.items()))
print(json.dumps(o))

Načítá se…
Zrušit
Uložit