Wednesday, November 25, 2015

How to enable tab completion on elements of lists and array-like objects in iPython (greedy completion)

One of iPython's most useful features is tab completion: You start typing the name of a variable / function / module, then hit the TAB key and let iPython show you a list of potential matches.

However, what if you want to do the same on an array-like object?

[In 1] my_array[0].

Ask a Swiss!

What you are looking for is called greedy completion, and can be enabled with a line-oriented magic function. These work much like OS command-like calls. You simply type them into an iPython console:

[In 2] %config IPCompleter.greedy = True

This will enable completion on elements of lists, results of function calls, etc.

However, be warned that enabling this option can be unsafe, because the code is actually evaluated upon hitting TAB. This is why the feature is disabled by default.

No comments :

Post a Comment