ipython中列表元素的制表符完成

2024-04-24 11:28:18 发布

您现在位置:Python中文网/ 问答频道 /正文

下面是选项卡完成对我的工作方式:

In [84]: a="string"

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

字符串的Tab completion在此处工作:

^{pr2}$

列表的Tab completion在此处工作:

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

字符串的制表符补全在此处不起作用:

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和ipdbv0.8。谢谢


Tags: 方法字符串in列表stringindexcount方式
1条回答
网友
1楼 · 发布于 2024-04-24 11:28:18

创建ipython配置文件:

ipython profile create testing

在ipython_配置.py取消对此行的注释

^{pr2}$

使用此配置文件加载IPython:

ipython notebook  profile=testing

这为列表成员、字典键和值提供了制表符。在


一种快速的替代方法是使用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']

另一种方法是在ptv中使用Python或IPython交互式控制台或常规编辑器,它能够对列表元素执行补全(intellisense)。在

相关问题 更多 >