[IPython-user] Feature suggestion: %remember

Ville Vainio vivainio at gmail.com
Fri Dec 9 00:42:41 CST 2005


On 12/8/05, Fernando Perez <Fernando.Perez at colorado.edu> wrote:

> The problem is that pickle is notoriously finicky, and there are many
> innocuous-looking things in python which can NOT be pickled, so this function
> can fail at any time.

It's easy to test this by trying to pickle an object when you do
%remember - if it doesn't pickle correctly, it's not written to the
data structure. This would still break if the user remembered
something in a deleted module, but see below.

> failed to write.  But I'm not sure how useful such an unreliable tool would
> be, and with ipython I always resist putting in the core something which is
> too easy to break in everyday use.

It would only break other remembered variables (instead of them &
bookmarks) if I/someone hacked the persistence system in
iplib.post_config_initialization() and iplib.atexit_operations() to
use shelve instead of pickle/unpickle (probably a good idea anyway).

I see it as a rather risk-free operation with high potential for
enhancing the "seamless" user experience, a'la ancient systems where
all data was persisted... wasn't the "abc" language, an inspiration
for python, like this?

> So if you write it for your own purposes, by all means send it and I'll put it
> up on the wiki.  But until you can convince me that we can have this in the
> core and be _reliable_, I'm afraid I'll balk at it.

I believe I can convince you :-). Think of this as a generalization of
the bookmark functionality...

> ps - implementation tips: use shelve, atexit, and in your magic, store the
> list of names to be rememberd as a hidden var in the user namespace:
>
> self.shell.user_ns['__magic_remember'] = ....
>
> With these, the actual implementation should be very, very easy (if not robust
> due to the problems listed above).

There is already the "persist" member variable in iplib, I think I'll use it.

I think I'd also "remember" (i.e. shelve) the variable immediately on
the execution of %remember. I'd also enhance the bookmark
functionality to commit the created bookmark immediately, to avoid the
case where there are multiple ipython instances of ipython and the
last to close is the only one to get the bookmarks saved.

I believe this is good stuff and won't burn anyone, even people who
push the envelope and are willing to abuse the system. :-)

--
Ville Vainio    http://tinyurl.com/2prnb




More information about the IPython-user mailing list