[IPython-dev] looking for advice on a custom dict-like completer

Darren Dale dsdale24 at gmail.com
Sat Jan 31 19:13:12 EST 2009

Hi Fernando,

Thank you for the advice. I've been looking at this most of the day, and I
think I'm stuck. I have an object I'm trying to navigate:


What I think needs to happen is to register a completer that matches
r'.*?\[', split the string at first '[', ofind the base (dict_object), check
if its an dict object. Then if the last '[' occurs later than the last ']',
I know I am looking for a list of keys, so I split the original string the
last ']' and run eval(extendedbase, self.shell.user_ns) to yield the object
up to level_2, ask it for its list of keys, and return those keys. Its not
very elegant, and I've only implemented up to dict_object['lev<tab>. Now
imagine the following situation:


It's not clear to me how I would get the object at level_3 and then hook
into ipython's usual completion chain to filter attributes with leading
underscores, or the traits completer, for example. Is this possible?

On Sat, Jan 31, 2009 at 12:34 PM, Fernando Perez <fperez.net at gmail.com>wrote:

> Hey Darren,
> On Sat, Jan 31, 2009 at 6:37 AM, Darren Dale <dsdale24 at gmail.com> wrote:
> > Hi Fernando,
> >
> > I'm sorry to bother you. I posted not too long ago hoping to find some
> > advice on how to implement a custom completer for __getitem__ access of
> > dict-like objects in the h5py project, but I didnt get any responses. I
> > looked through the changelogs and the commit logs, trying to identify
> when
> > this type of completion was supported in IPython, but came up empty.
> No worries, it's no bother at all.  It's my fault that I've been
> mostly MIA recently on pretty much all public mailing lists,  I've
> just been swamped with real life/work things.  But I'm trying to
> recover a bit now :)  I've cc'd the user list so this reply is
> actually archived.
> > If (and only if) you have time, would you be able to provide some advice
> or
> > direct me to some code in an old version of IPython so I could see how it
> > was originally done?
> I did a bit of archaeological digging, and found that 0.4 has what you
> want:
> maqroll[scripts]> python2.4 ipython
> Python 2.4.5 (#2, Aug  1 2008, 02:20:59)
> Type "copyright", "credits" or "license" for more information.
> IPython 0.4.0 -- An enhanced Interactive Python.
> ?       -> Introduction to IPython's features.
> @magic  -> Information about IPython's 'magic' @ functions.
> help    -> Python's own help system.
> object? -> Details about 'object'. ?object also works, ?? prints more.
> In [1]: a={'key':'value'}
> In [2]: a['key']
> Out[2]: 'value'
> In [3]: a['key'].r<<TAB HERE>>
> a['key'].replace  a['key'].rindex   a['key'].rsplit
> a['key'].rfind    a['key'].rjust    a['key'].rstrip
> ###
> Note that you'll need to run it as I did above, with python2.4,
> because at the time we didn't declare the encoding of the files and
> python2.5 considers that an error (my name has an accent in unicode).
> You can find ipython 0.4 here, along with a bunch of other old
> versions in that directory:
> http://ipython.scipy.org/dist/old/ipython-0.4.0.tgz
> I'd start by looking at FlexCompleter.py in there, though there may be
> a bit more elsewhere.  I hope this helps, do let me know if you need
> anything else.
> Cheers,
> f
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20090131/0e4dcee9/attachment.html>

More information about the IPython-dev mailing list