对于以下情况,我希望在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/