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 寧夏 銀川