I like IPython, but I’m not sure I understand it, and my lack of understanding has caused me some pain recently when a pickle file (Python object serialization for the uninitiated) would not open. I’m not even sure I’ve figured out how to reproduce the problem, but I did find a very simple example of some code that runs fine in Python but not IPython:
Running this with
gives:
stober[~/Dropbox/workspace/gist]{laptop}$ python ipickle.py
<__main__.A instance at 0x10cc37bd8>
Running the same thing with IPython
produces decidedly different output:
stober[~/Dropbox/workspace/gist]{laptop}$ ipython ipickle.py
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
/Users/stober/Dropbox/workspace/gist/ipickle.py in <module>()
16 pickle.dump(A(), open("A.pck","w"))
17
---> 18 a = pickle.load(open("A.pck"))
19 print a
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.pyc in load(file)
1376
1377 def load(file):
-> 1378 return Unpickler(file).load()
1379
1380 def loads(str):
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.pyc in load(self)
856 while 1:
857 key = read(1)
--> 858 dispatch[key](self)
859 except _Stop, stopinst:
860 return stopinst.value
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.pyc in load_inst(self)
1067 module = self.readline()[:-1]
1068 name = self.readline()[:-1]
-> 1069 klass = self.find_class(module, name)
1070 self._instantiate(klass, self.marker())
1071 dispatch[INST] = load_inst
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.pyc in find_class(self, module, name)
1124 __import__(module)
1125 mod = sys.modules[module]
-> 1126 klass = getattr(mod, name)
1127 return klass
1128
AttributeError: 'FakeModule' object has no attribute 'A'