use ipython to get REAL code-completion in pycharm

孤者浪人 提交于 2019-12-05 01:36:18

I had the same question, I found the answer here: https://www.jetbrains.com/pycharm/help/using-ipython-notebook-with-pycharm.html

What you need to do is to create a ipython notebook in the project tool window. This is a file with the extension '.ipynb'. Right click on the directory where you want to put the file, select 'New-->File', enter a file name in the dialog box and give the file extension .ipynb. Open the notebook file and when you start to type something in the window, a drop down window appears with objects in the namespace plus any commands that start with the letters already typed.

It cannot tell what returns are from functions(with out actually running the script, thats why ipython knows what it is (it has actually run the code and recieved back an object it can introspect)

if you want code completion without having to actually execute your script up to where you are entering text you have to do an extra step

import numpy as np
m = np.random.random((3,5))
assert isinstance(m,np.ndarray)
m. #now you get code completion (since the IDE now knows the class of m, without having to execute your script)

To achieve iPython like functionality in pycharm, you can do it two ways:

  1. setup a breakpoint, and debug your code. when it reaches the breakpoint, go to the console tab right below the editor, and launch a command line by clicking the button that says show command line

  2. Launch a python command line from your console (without running debugger), by clicking on Tools, Run Python console

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!