Python
yaml库不支持读取文档中嵌入的yaml。这是一个提取yaml文本的实用程序函数,因此您可以在读取文件的其余部分之前对其进行解析:
#!/usr/bin/python2.7import yamlimport sysdef get_yaml(f): pointer = f.tell() if f.readline() != '---n': f.seek(pointer) return '' readline = iter(f.readline, '') readline = iter(readline.next, '---n') return ''.join(readline)for filename in sys.argv[1:]: with open(filename) as f: config = yaml.load(get_yaml(f)) text = f.read() print "TEXT from", filename print text print "ConFIG from", filename print config
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)