說明:
請撰寫一程式,讀取勞保投保薪資分級表read.json內的資料後,將資料轉存為write.yaml。
檔案連結:read.json (請另存檔案,必須與程式同一資料夾)
範例輸出:

程式碼:
import json
with open('read.json','r',encoding='utf-8') as fp:
dict1 = json.loads( fp.readline() )
with open('write.yaml','w',encoding='utf-8') as fp:
for i in range( len( dict1 ) ):
fp.write('- 投保薪資等級: {}\n'.format( dict1[i]['投保薪資等級'] ) )
fp.write(' 月投保薪資: {}\n'.format( dict1[i]['月投保薪資'] ) )
fp.write(' 月薪資總額: {}\n'.format( dict1[i]['月薪資總額'] ) )
fp.write(' 身分別: {}\n'.format( dict1[i]['身分別'] ) )
沒有留言:
張貼留言