import yaml #向yaml文件中写 with open("E:个人 rename.yaml", 'w') as f: project = {'在远方':"1214", "宁夏":"银川","test":'txt'} yaml.dump(project,f) #读取yaml文件中的内容 with open("E:个人 rename.yaml") as ff: temp = yaml.load(ff.read(),Loader=yaml.FullLoader) for key,values in temp.items(): print(key," ",values)
output:
test txt 在远方 1214 宁夏 银川