码迷,mamicode.com
首页 > 编程语言 > 详细

python 初学(json pickle shelve)

时间:2019-01-20 16:03:05      阅读:204      评论:0      收藏:0      [点我收藏+]

标签:author   def   port   color   dump   open   write   pre   int   

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)

标签:author   def   port   color   dump   open   write   pre   int   

原文地址:https://www.cnblogs.com/mlllily/p/10294900.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!