Skip to content

Commit 7740e8c

Browse files
author
Dvij
committed
1 parent 8f605e1 commit 7740e8c

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

‎lib/matplotlib/pyplot.py‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,46 @@ def ion():
170170
'Turn interactive mode on.'
171171
matplotlib.interactive(True)
172172

173+
def pickle_save(obj, f=None, protocol=0):
174+
"""
175+
Write a pickled representation of obj as a string or a file depending on the number and type of arguments used.
176+
177+
``pickle_save(obj, file, protocol)`` Write a pickled representation of obj to the open file object file.
178+
179+
``pickle_save(obj, protocol)`` Return the pickled representation of the object as a string, instead of writing it to a file.
180+
"""
181+
import pickle
182+
183+
if not f:
184+
return pickle.dumps(obj, protocol)
185+
186+
pickle.dump(obj, f, protocol)
187+
188+
def pickle_load(*args, **kwargs):
189+
"""
190+
Read a string or pickled object and reconstruct the original object hierarchy.
191+
192+
``pickle_load(file)`` Read a string from the open file object file and interpret it as a pickle data stream, reconstructing and returning the original object hierarchy.
193+
194+
``pick_load(str)`` Read a pickled object hierarchy from a string. Characters in the string past the pickled object’s representation are ignored.
195+
196+
"""
197+
import pickle
198+
199+
state = isinteractive()
200+
if state:
201+
ioff()
202+
if len(args) != 1 or not(isinstance(args[0], str) or isinstance(args[0], file)):
203+
warnings.warn('Unsupported number/type of argument(s).')
204+
if isinstance(args[0], str):
205+
unpickledobj = pickle.loads(args[0])
206+
if state:
207+
ion()
208+
return unpickledobj
209+
210+
pickle.load(args[0])
211+
if state:
212+
ion()
173213

174214
def pause(interval):
175215
"""

0 commit comments

Comments
 (0)