当前位置:首页 > python教程 > python技巧

Python读写Json文件


一个小例子,使用json配置文件

 

            #
             -*- coding: utf-8 -*-
            import  json

            import  time

            def
             store(data):
    with open(
            ‘
            data.json
            ‘, ‘w‘) as json_file:
        json_file.write(json.dumps(data))

def load():
    with open(‘data.json‘) as json_file:
        data = json.load(json_file)
        return data



if__name__ == "__main__":

    data = {}
    data["last"]=time.strftime("%y%m%d")
    store(data)

    data = load()
    print data["last"]

【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!