using snippet below, have added tab completion python interpreter.
import readline import rlcompleter if 'libedit' in readline.__doc__: readline.parse_and_bind("bind ^i rl_complete") else: readline.parse_and_bind("tab: complete")
however, have encountered weird behaviour after hitting tab, interpreter give duplicates such:
python 2.7.3 (v2.7.3:70274d53c1dd, apr 9 2012, 20:52:43) [gcc 4.2.1 (apple inc. build 5666) (dot 3)] on darwin type "help", "copyright", "credits" or "license" more information. >>> d=dict() >>> d. display 108 possibilities? (y or n) d.__class__( d.__class__( d.__class__( d.__class__( d.__cmp__( d.__cmp__( d.__contains__( d.__contains__( d.__delattr__( d.__delattr__( d.__delattr__( d.__delitem__( d.__delitem__( d.__doc__ d.__doc__ d.__doc__ d.__eq__( d.__eq__( d.__format__( d.__format__( d.__format__( d.__ge__( d.__ge__( d.__getattribute__( d.__getattribute__( d.__getattribute__( d.__getitem__( d.__getitem__( d.__gt__( d.__gt__( d.__hash__ d.__hash__ d.__hash__ d.__init__( d.__init__( d.__init__( d.__iter__( d.__iter__( d.__le__( d.__le__( d.__len__( d.__len__( d.__lt__( d.__lt__( d.__ne__( d.__ne__( d.__new__( d.__new__( d.__new__( d.__reduce__( d.__reduce__( d.__reduce__( d.__reduce_ex__( d.__reduce_ex__( d.__reduce_ex__( d.__repr__( d.__repr__( d.__repr__( d.__setattr__( d.__setattr__( d.__setattr__( d.__setitem__( d.__setitem__( d.__sizeof__( d.__sizeof__( d.__sizeof__( d.__str__( d.__str__( d.__str__( d.__subclasshook__( d.__subclasshook__( d.__subclasshook__( d.clear( d.clear( d.copy( d.copy( d.fromkeys( d.fromkeys( d.get( d.get( d.has_key( d.has_key( d.items( d.items( d.iteritems( d.iteritems( d.iterkeys( d.iterkeys( d.itervalues( d.itervalues( d.keys( d.keys( d.pop( d.pop( d.popitem( d.popitem( d.setdefault( d.setdefault( d.update( d.update( d.values( d.values( d.viewitems( d.viewitems( d.viewkeys( d.viewkeys( d.viewvalues( d.viewvalues(
108 possibilities! min 2, max 4 duplicates.
furthermore,
- if subclass
dict
total number of possibilities increases 160 (and 209, 258). - if type enough characters tab nail command, without displaying duplicates.
any pointers or debugging tips appreciated.
i have solved issue adding custom completer. works expected.
import readline import rlcompleter c = rlcompleter.completer() def complete(text, state): buffer = readline.get_line_buffer() first = c.complete(buffer, 0) if state == 0: return first current = c.complete(buffer, state) if current != first: return current readline.parse_and_bind('bind ^i rl_complete') readline.set_completer(complete)
Comments
Post a Comment