zoukankan      html  css  js  c++  java
  • json序列化

    #!/usr/bin/env python
    # -*- coding:utf-8 -*-
    # Author:Random_lee
    #pickle只能在python中使用,可以序列化函数的内存地址
    #json可以在多语言中使用,但是只能做简单的序列化


    # import json
    import pickle

    def sayhai(name):
    print('hello',name)


    info={
    'name':'randomlee',
    'age':'24',
    'sex':'man',
    'func':sayhai
    }

    # f=open('test.text','w')
    # # print(json.dumps(info))
    # f.write(json.dumps(info))
    # f.close()

    f=open('test.text','bw')
    print(pickle.dumps(info))
    f.write(pickle.dumps(info))
    f.close()


    #!/usr/bin/env python
    # -*- coding:utf-8 -*-
    # Author:Random_lee

    import pickle

    def sayhai(name):
    print('hello',name)


    info={
    'name':'randomlee',
    'age':'24',
    'sex':'man',
    'func':sayhai
    }

    f=open('test1.text','wb')
    pickle.dump(info,f) #f.write(pickle.dumps(info))
    f.close()



    #!/usr/bin/env python
    # -*- coding:utf-8 -*-
    # Author:Random_lee

    # import pickle
    import json


    # def sayhai(name):
    # print('hello',name)


    info={
    'name':'randomlee',
    'age':'24',
    'sex':'man',
    'func':'sayhai'
    }

    f=open('test3.text','w')
    f.write(json.dumps(info))

    # info['age']=22
    # f.write(json.dumps(info))

    f.close()

  • 相关阅读:
    投票练习
    多条件查询
    PHP 购物车
    PHP TP模型
    PHP smarty函数
    PHP smarty复习
    PHP smarty缓存
    PHP phpcms
    php smarty查询分页
    PHP Smarty变量调节器
  • 原文地址:https://www.cnblogs.com/randomlee/p/8686192.html
Copyright © 2011-2022 走看看