代码语言:javascript复制
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import json
import collections
def readMd(mdfile):
with open(mdfile) as f:
lines = f.readlines()
lines = list(map(lambda l: l.rstrip(), lines))
d = collections.OrderedDict({line: '' for line in lines})
json_str = json.dumps(d)
return json_str
def readJson(json_str):
ordered_dict = json.loads(json_str, object_pairs_hook=collections.OrderedDict)
print(ordered_dict)
if __name__ == '__main__':
json_str = readMd('README.md')
readJson(json_str)