Permalink
Browse files

added pickle

  • Loading branch information...
1 parent 73fbbcb commit 5013b654ad4511f332c2d0aaa84a4a73532d6cb5 @stinsong4100 stinsong4100 committed Mar 9, 2012
Showing with 32 additions and 12 deletions.
  1. +32 −12 wish_we_had_known/index.rst
View
44 wish_we_had_known/index.rst
@@ -25,18 +25,6 @@ debugger, the commands you will want to use can be abreviated to 1 character::
n: run just the next line
-Matplotlib Gallery
-------------------
-
-When you Google any Matplotlib function, you get directed to this endless
-webpage that takes forever to load. It is generally much better to go
-http://matplotlib.sourceforge.net/gallery.html or http://www.scipy.org/Cookbook/Matplotlib
-
-Or else when you're in python use the ``?`` help functionality::
-
- In[4]: plt.plot?
-
-
Catching Errors (try/except)
---------------------------
@@ -52,4 +40,36 @@ an error, you can put it in a try statement and tell except to do something
You can have except catch only certain errors if you want.
+Pickle
+------
+
+It is very usful to save some of the data that you derive in python for later
+use. Pickle is the way to do this in Python. For example, if your data
+is in some big file that takes a long time to load and you just want the
+profile of some object in it.
+It is easy to save a dictionary::
+
+ import pickle
+ pickle.dump({'data1':[1,234,6902,3496]},open('outputfile.pkl','w'))
+
+Note that pickle needs to be sent a file object which can be created with
+the open method.
+
+Then to load that data back in later
+
+ d = pickle.load(open('outputfile.pkl'))
+ d['data1']
+
+Matplotlib Gallery
+------------------
+
+When you Google any Matplotlib function, you get directed to this endless
+webpage that takes forever to load. It is generally much better to go
+http://matplotlib.sourceforge.net/gallery.html or http://www.scipy.org/Cookbook/Matplotlib
+
+Or else when you're in python use the ``?`` help functionality::
+
+ In[4]: plt.plot?
+
+
:Author: Originally written by Tom Aldcroft, with changes by Tom Robitaille and Neil Crighton.

0 comments on commit 5013b65

Please sign in to comment.