2015-07-12 9 views
7

这里是tab完成是如何工作对我来说:Tab键完成对列表中的元素

In [84]: a="string" 

In [85]: b = ["str", "ing"] 

Tab补齐字符串正在这里:

In [86]: a. 
a.capitalize a.decode  a.expandtabs a.index  a.isdigit  a.istitle  a.ljust  a.partition a.rindex  a.rsplit  a.splitlines a.swapcase a.upper  
a.center  a.encode  a.find  a.isalnum  a.islower  a.isupper  a.lower  a.replace  a.rjust  a.rstrip  a.startswith a.title  a.zfill  
a.count  a.endswith a.format  a.isalpha  a.isspace  a.join  a.lstrip  a.rfind  a.rpartition a.split  a.strip  a.translate 

Tab键完成对列表正在这里:

In [86]: b. 
b.append b.count b.extend b.index b.insert b.pop  b.remove b.reverse b.sort  

Tab补齐字符串不工作在这里:

In [87]: b[0]. 

一个可能的解决方法:

In [88]: c = b[0] 

In [89]: c. 
c.capitalize c.decode  c.expandtabs c.index  c.isdigit  c.istitle  c.ljust  c.partition c.rindex  c.rsplit  c.splitlines c.swapcase c.upper  
c.center  c.encode  c.find  c.isalnum  c.islower  c.isupper  c.lower  c.replace  c.rjust  c.rstrip  c.startswith c.title  c.zfill  
c.count  c.endswith c.format  c.isalpha  c.isspace  c.join  c.lstrip  c.rfind  c.rpartition c.split  c.strip  c.translate 

是否有可能使用完成,而且没有提到的解决方法吗?我在ipdb中遇到类似的行为,是否有可能修复这种行为呢?我使用ipythoon v3.1.0和ipdb v 0.8。由于

回答

5

创建IPython的轮廓:

ipython_config.py
ipython profile create testing 

取消注释此行

# 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.IPCompleter.greedy = True 

负载IPython的与此配置文件:

ipython notebook --profile=testing 

这给了TAB完成列表成员和字典键和值。


一个快速的替代方法是使用DIR()方法:

dir(b[0]) 

#returns: 

['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__getslice__', '__gt__', '__hash__', '__init__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '_formatter_field_name_split', '_formatter_parser', 'capitalize', 'center', 'count', 'decode', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'index', 'isalnum', 'isalpha', 'isdigit', 'islower', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill'] 

另一种方法是使用Python或IPython的交互式控制台或PTVS规则编辑器,这是能够做到的完成(intellisense)列表元素。

+0

是的,但这是另一种解决方法。主要目标是使用Tab键。一些配置像bash的/ etc/bash_completion会很好 –

+0

显然这个工作在PTVS IDE – denfromufa

+0

ipython autocompletion被认为是使用jedi重构的:https://github.com/ipython/ipython/issues/8606 – denfromufa