-
Notifications
You must be signed in to change notification settings - Fork 14
Python object serialization
lanzhiwang edited this page Sep 30, 2019
·
7 revisions
import json
<str> = json.dumps(<object>, ensure_ascii=True, indent=None)
<object> = json.loads(<str>)
from collections import OrderedDict
<object> = json.loads(<str>, object_pairs_hook=OrderedDict)
def read_json_file(filename):
with open(filename, encoding='utf-8') as file:
return json.load(file)
def write_to_json_file(filename, an_object):
with open(filename, 'w', encoding='utf-8') as file:
json.dump(an_object, file, ensure_ascii=False, indent=2)
import pickle
<bytes> = pickle.dumps(<object>)
<object> = pickle.loads(<bytes>)
def read_pickle_file(filename):
with open(filename, 'rb') as file:
return pickle.load(file)
def write_to_pickle_file(filename, an_object):
with open(filename, 'wb') as file:
pickle.dump(an_object, file)
-
Awesome huzhi
-
Python
-
Linux
-
MySQL
-
Component
-
分布式
-
PHP
-
go
-
Android 逆向
-
机器学习
-
计算机基础
-
JavaScript
-
Internet Awesome
-
Other
-
Book