Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPython Code Completion / Intellisense on Dot Possible?

Tags:

python

ipython

As someone trying to learn the ins and outs of Python (with emphasis on scientific computing - ie: pandas, numpy, scikit-learn), most of the gurus out there seem to recommend and use iPython notebooks. My biggest sticking point as a beginner/intermediate coder is that I NEED code completion / intellisense -like functionality from an IDE to learn the function parameters. I'm not hard-wired yet to just know what parameters are available at my current development.

In iPython, I noticed I can press Tab to show the drop-down of options (seen below as pd.) but I don't want to have to hit each time. That's not user-friendly for my needs. Instead, I would like it to show only available classes and methods when I press dot.

Secondly, I notice that if I did say pd.read_csv(<TAB>, I get a lot more options than are the actual parameters in read_csv.

Question: Can iPython automatically show accurate code completion options instantly after pressing dot / period? Also, is there a way to configure it to only show the available function parameters when within a function?

To make this question super-specific, I'm not asking about using any other IDE; I'm asking very specifically in regards to just iPython and wondering if there's a way to set some kind of configuration to achieve accurate "dot" display options instantly when pressing "dot" (no time delay).

enter image description here

Example below shows Desktop which is obviously not a parameter of pd.read_csv().

enter image description here

like image 210
Jarad Avatar asked Nov 13 '15 19:11

Jarad


People also ask

Does IPython have tab completion feature?

Latex and Unicode completion IPython and compatible frontends not only can complete your code, but can help you to input a wide range of characters. In particular we allow you to insert a unicode character using the tab completion mechanism.

Does Jupyter have autocomplete?

You have auto-complete in Jupyter notebooks like you have in any other Jupyter environment. Simply hit the “Tab” key while writing code. This will open a menu with suggestions. Hit “Enter” to choose the suggestion.

Does JupyterLab have code completion?

To enable code autocomplete in Jupyter Notebook or JupyterLab, you just need to hit the Tab key while writing code. Jupyter will suggest a few completion options. Navigate to the one you want with the arrow keys, and hit Enter to choose the suggestion.

How do I turn on autocomplete in Python?

(In Python Shell window, you can use TAB key besides the key combination of 'CTRL' and 'space' to invoke the built-in auto-completion feature.) Alternatively, you can choose the "Show Completions" in the main Edit menu to achieve the same as well.


2 Answers

You can press <Shift>-<Tab> to get a tooltip showing the function's signature:

enter image description here

Alternatively, invoking zip? opens a documentation pane at the bottom of the window.

As far as having the tooltip open automatically, I'm unsure. I'd guess that it isn't possible via configuration.

like image 113
jme Avatar answered Sep 19 '22 00:09

jme


Almost 3 years later, I've finally come across a potential solution.

Answer: Install nbextensions and enable the Hinterland extension.

Enable code autocompletion menu for every keypress in a code cell, instead of only calling it with tab.

Here's what you do:

  1. pip install jupyter_contrib_nbextensions
  2. jupyter contrib nbextension install --user
  3. Start jupyter notebook (browser launches)
  4. One of the tabs should now show "Nbextensions"
  5. There, you will find "Hinterland". Check the box to enable.

Hinterland has some adjustable options like:

  • hinterland.hint_delay: delay in milliseconds between keypress & hint request.
  • hinterland.enable_at_start: Whether to enable hinterland's continuous hinting when notebook is first opened, or if false, only when selected from the help-menu item.
  • hinterland.hint_inside_comments: Whether to request hints while typing code comments. Defaults to false.
  • Other regex options: hinterland.exclude_regexp, hinterland.include_regexp, hinterland.tooltip_regexp

enter image description here

like image 43
Jarad Avatar answered Sep 19 '22 00:09

Jarad