Note that there are some explanatory texts on larger screens.

plurals
  1. POTab-completion in Python interpreter in OS X Terminal
    primarykey
    data
    text
    <p>Several months ago, I wrote a <a href="http://igotgenes.blogspot.com/2009/01/tab-completion-and-history-in-python.html" rel="noreferrer">blog post</a> detailing how to achieve tab-completion in the standard Python interactive interpreter--a feature I once thought only available in IPython. I've found it tremendously handy given that I sometimes have to switch to the standard interpreter due to IPython unicode issues.</p> <p>Recently I've done some work in OS X. To my discontent, the script doesn't seem to work for OS X's Terminal application. I'm hoping some of you with experience in OS X might be able to help me trouble-shoot it so it can work in Terminal, as well.</p> <p>I am reproducing the code below</p> <pre><code>import atexit import os.path try: import readline except ImportError: pass else: import rlcompleter class IrlCompleter(rlcompleter.Completer): """ This class enables a "tab" insertion if there's no text for completion. The default "tab" is four spaces. You can initialize with '\t' as the tab if you wish to use a genuine tab. """ def __init__(self, tab=' '): self.tab = tab rlcompleter.Completer.__init__(self) def complete(self, text, state): if text == '': readline.insert_text(self.tab) return None else: return rlcompleter.Completer.complete(self,text,state) #you could change this line to bind another key instead tab. readline.parse_and_bind('tab: complete') readline.set_completer(IrlCompleter('\t').complete) # Restore our command-line history, and save it when Python exits. history_path = os.path.expanduser('~/.pyhistory') if os.path.isfile(history_path): readline.read_history_file(history_path) atexit.register(lambda x=history_path: readline.write_history_file(x)) </code></pre> <p>Note that I have slightly edited it from the version on my blog post so that the <code>IrlCompleter</code> is initialized with a true tab, which seems to be what is output by the Tab key in Terminal.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload