使用ipython在pycharm中获得REAL代码完成 [英] use ipython to get REAL code-completion in pycharm

查看:226
本文介绍了使用ipython在pycharm中获得REAL代码完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

许多python IDE都提供代码完成(代码洞察),PyCharm是其中一个IDE。但是,在我看来,提供的代码完成非常有限。让我举个例子来说清楚:

Many python IDE's boasts of providing code-completion (code insight), PyCharm is one of those IDE's. However, it seems to me that the provided code-completion is extremely limited. Let me give you an example to make it clear:

import numpy as np
m = np.random.random((3,5))
m.

在'm。'之后点击CTRL空格不会给我任何代码完成 - 无所谓我有多努力;)..我猜这是因为IDE必须进行类型推断以了解变量'm'的类型,并且这在动态编程语言领域并不简单。

Hitting CTRL-space after 'm.' will not give me any code-completion, -no matter how hard I hit it ;).. I guess this is because the IDE would have to do type inference to know the type of the variable 'm', and that this isn't trivial in the domain of dynamic programming languages.

现在,PyCharm提供了一个名为收集代码洞察的运行时类型信息的设置,这听起来确实很有希望。但是,它似乎没有解决上面提到的问题..我仍然无法在变量'm'上获得代码完成。

Now, PyCharm comes with a setting called "Collect run-time types information for code insight", which indeed sounds promising. However, it doesn't seem to fix the problem mentioned above.. I am still not able to get code-completion on the variable 'm'.

到目前为止,我只找到一种方法来在PyCharm中获取变量的代码完成:

Thus far, I have only found one way to get code-completion on variables in PyCharm:

import numpy as np
m = np.random.random((3,5))
''':type : np.matrix'''
m.

在这个例子中,我可以在'm'后按CTRL空格时获得代码完成。 ,这是因为我通过使用docstring指定变量的类型来帮助IDE。但是,我对这种获取代码完成的方式不满意,因为它为所有这些文档字符串添加了不必要的冗长(更不用说所有额外的键盘输入了)......

In this example I am able to get code-completion when pressing CTRL-space after 'm.', and this is because I am helping the IDE by specifying the type of the variable with a docstring. I am, however, not satisfied with this way of getting code-completion, because it adds unnecessary verbosity to the code with all these docstrings (not to mention all the extra keyboard-typing)...

现在,如果我们在linux终端启动IPython,并输入第一块代码,我们将能够一直获得代码完成,即使是变量'm'。 (通过按TAB而不是CTRL空格来实现IPython中的代码完成)..

Now, if we start IPython in a linux-terminal, and enter the first piece of code, we will be able to get code-completion all the way, -even for the variable 'm'. (where the code-completion in IPython is achieved by pressing TAB instead of CTRL-space)..

我对IPython没有多少经验,但是我相信我已经听说过有关IPython不断在循环中执行代码的事情或类似的东西...

我在想它应该是可以使用IPython在PyCharm编辑器中的所有变量上实现REAL代码完成....

I am thinking that it should be possible to use IPython to achieve REAL code-completion on all variables in the editor of PyCharm....

有没有办法设置PyCharm来使用IPython代码完成?

请注意,我不满意将代码发送到终端窗口/控制台,或类似的东西,我希望在PyCharm的编辑器中完成代码...

我看过这样的问题在Pycharm Ubuntu中添加ipython作为解释器,但似乎是在控制台中使用IPython, - 不在编辑器中...在IDE中也有很多关于代码完成的问题,但它们似乎都有与PyCharm相同的令人不满意的代码完成级别......

I have looked at questions like this Adding ipython as an interpreter in Pycharm Ubuntu, but it seems to be about using IPython in the console, -not in the editor... There are also plenty of questions talking about code-completion in IDE's, but they all seem to have the same unsatisfying level of code-completion as PyCharm...


  • 操作系统:Debian测试

  • python:Python3和IPython3

  • IDE:Pycharm 3.0.2专业版

推荐答案

我有同样的问题,我在这里找到答案:
https://www.jetbrains.com/pycharm/help/using-ipython-notebook-with-pycharm.html

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

你是什么需要做的是在项目工具窗口中创建一个ipython笔记本。这是一个扩展名为.ipynb的文件。右键单击要放置文件的目录,选择新建 - >文件,在对话框中输入文件名,并提供文件扩展名.ipynb。打开笔记本文件,当您开始在窗口中键入内容时,会出现一个下拉窗口,其中包含命名空间中的对象以及以已键入的字母开头的所有命令。

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.

这篇关于使用ipython在pycharm中获得REAL代码完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆