Ipython autocomplete for list or dict objects

I would like to have autocomplete in IPython (Jupyter qtconsole or console) for the following case:

I create a class

class MyClass(object): def __init__(self, a, b): self.a = a self.b = b 

and put some objects of this class in a list or dict

 my_list = [] my_list.append(MyClass(2,3)) my_list.append(MyClass(9,2)) my_list.append(MyClass(8,4)) 

Now if i do

 my_list[0].TAB 

autocomplete does not work.

I would like to see a list of my class attributes and methods. Am I missing something or is it just not supported in IPython?

Appreciate your help ...

+6
source share
1 answer

You can do this in the cell of your Jupyter laptop:

 %config IPCompleter.greedy=True 

What gives (in ipython / jupyter console, but same thing in laptop)

 In [10]: my_list[0].<TAB> my_list[0].a my_list[0].b 

To have it forever, just edit the ipython_config.py file to look like this (comment lines are already present and unmodified around lines 506-514):

 #------------------------------------------------------------------------------ # Completer configuration #------------------------------------------------------------------------------ # Activate greedy completion # # This will enable completion on elements of lists, results of function calls, # etc., but can be unsafe because the code is actually evaluated on TAB. c.Completer.greedy = True # <-- uncomment this line and set it to True 

If you don't have ipython_config.py in ~/.ipython/profile_default/ , you can create it with

 ipython profile create 
+10
source

All Articles