by zeroimpl · 4y ago · 0 comments
cpu: 0.2
kb_read_s: 0.12
mac_addr: 10:AA:FF:00:55:66 dict((key.strip(), val.strip()) for key, _, val in line.strip().partition(‘:’) for line in text.split(‘\n’) if line and line.strip())
Also who says we can’t have a universal parser for this format just like we have for JSON? Not everyone needs to write the one liner like above, just use the libtextformat.parse(text) or whatever we would call it. {program -> human-text -> parser}+
When it could look like this: program
-> {struct-text -> program}+
[-> formatter] -> human-text . json.parse(input)Type support is lacking. Not date support for example.
Unnecessary quotes around keys make it harder for humans to read.
Different implementations allow for repeated keys.
otherformat.parse(input) // just as reasonable cut -d: -f2-