python 初学(json pickle shelve)

Posted mlllily

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 初学(json pickle shelve)相关的知识,希望对你有一定的参考价值。

json:

# _author: lily
# _date: 2019/1/19

import json

my_dict = {name: lily, age: 18}
f = open(JSON_text, w)

# data = json.dumps(my_dict)
# f.write(data)
# 上面两句等价于
json.dump(my_dict, f)

f.close()
# _author: lily
# _date: 2019/1/20

import json

f = open(JSON_text, r)

# data = f.read()
# my_dict = json.loads(data)
# 上面两句话等价于
my_dict = json.load(f)

print(my_dict[name])
f.close()

pickle:

# _author: lily
# _date: 2019/1/20

import pickle

def foo():
    print(ok)

data = pickle.dumps(foo)
f = open(PICKLE_text, wb)
f.write(data)
f.close()
# _author: lily
# _date: 2019/1/20

import pickle

def foo():
    print(okok)

f = open(PICKLE_text, rb)
data = f.read()

data = pickle.loads(data)

data()

f.close()

shelve:

# _author: lily
# _date: 2019/1/20

import shelve

# f = shelve.open(‘SHELVE_text‘)
# f[‘info‘] = {‘name‘: ‘lily‘, ‘age‘: 18}


f = shelve.open(SHELVE_text)
data = f.get(info)
print(data[name])

 

以上是关于python 初学(json pickle shelve)的主要内容,如果未能解决你的问题,请参考以下文章

python-函数式编程,反射,random,md5,pickle,json,re,time

python json and pickle

python json and pickle

python常用模块之json和pickle模块

Python json和pickle模块

python之json&pickle