ipython - Ipython自动补全对象列表或字典

标签 ipython ipython-notebook jupyter qtconsole

对于以下情况,我希望在IPython(Jupyter qtconsole或控制台)中具有自动补全功能:

我创建一个类(class)

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

并将该类的几个对象放入列表或字典
my_list = []
my_list.append(MyClass(2,3))
my_list.append(MyClass(9,2))
my_list.append(MyClass(8,4))

现在,如果我愿意
my_list[0].TAB

自动补全功能不起作用。

我想查看我的类属性和方法的列表。我是否缺少某些内容,或者IPython不支持此功能?

感谢您的帮助 ...

最佳答案

您可以在Jupyter Notebook的单元格中执行该操作:

%config IPCompleter.greedy=True

给出(在ipython/jupyter控制台中,但在笔记本中相同)
In [10]: my_list[0].<TAB>
my_list[0].a  my_list[0].b  

要永久拥有它,只需编辑文件ipython_config.py,使其看起来像这样(注释行已存在并且未修改,围绕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

如果ipython_config.py中没有~/.ipython/profile_default/,则可以使用以下方法创建一个:
ipython profile create

关于ipython - Ipython自动补全对象列表或字典,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33498591/

相关文章:

vim - ipython笔记本中的vi快捷方式

python - 导入错误 : cannot import name 'BatchNormalization' from 'tensorflow.python.keras.layers'

python - 子进程的 ipython 笔记本输出

python - 如果表达式包含 sympy 对象,则 Lambdify 表达式在与数组一起使用时引发 TypeError

python - 如何在没有终端提示的情况下从 IPython session 中复制

python - 如何解释Python中的timeit命令

matplotlib - 在 IPython Notebook 中缩放散点图

python - 更改 Jupyter 笔记本版本 4.x+ Logo

python - Windows下Jupyter中的kernel-1234.json在哪里?

css - Docker 主题 Jupyter