fre*_*red 6 ipython ipython-notebook qtconsole jupyter
我想在IPython(Jupyter qtconsole或控制台)中自动完成以下情况:
我创建了一个类
class MyClass(object):
def __init__(self, a, b):
self.a = a
self.b = b
Run Code Online (Sandbox Code Playgroud)
并将此类的几个对象放入列表或词典中
my_list = []
my_list.append(MyClass(2,3))
my_list.append(MyClass(9,2))
my_list.append(MyClass(8,4))
Run Code Online (Sandbox Code Playgroud)
现在,如果我这样做
my_list[0].TAB
Run Code Online (Sandbox Code Playgroud)
自动完成功能无效.
我想看一下我的类属性和方法的列表.我错过了什么,或者这只是不支持IPython?
感谢您的帮助 ...
jrj*_*rjc 10
您可以在Jupyter Notebook的单元格中执行该操作:
%config IPCompleter.greedy=True
Run Code Online (Sandbox Code Playgroud)
这给出了(在ipython/jupyter控制台中,但在笔记本中相同)
In [10]: my_list[0].<TAB>
my_list[0].a my_list[0].b
Run Code Online (Sandbox Code Playgroud)
要永久保存它,只需编辑您的文件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
Run Code Online (Sandbox Code Playgroud)
如果您没有ipython_config.py
,~/.ipython/profile_default/
可以创建一个:
ipython profile create
Run Code Online (Sandbox Code Playgroud)