簡體   English   中英

在ipython中為列表元素完成選項卡

[英]Tab completion in ipython for list elements

標簽完成對我有用:

In [84]: a="string"

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

字符串的標簽完成在這里工作:

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   

列表的標簽完成在這里工作:

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和ipdb v 0.8。 謝謝

創建ipython配置文件:

ipython profile create testing

ipython_config.py中取消注釋此行

# 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']

另一種方法是在PTVS中使用Python或IPython交互式控制台或常規編輯器,它能夠對列表元素進行完成(intellisense)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM