TQC+ 網頁資料擷取與分析 Python 3 _ 103 勞保投保薪資分級表

程式所產出的檔案,須輸出與程式同一層資料夾。

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

程式碼:
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]['身分別'] ) )

沒有留言:

張貼留言