Tab completion

Steven D'Aprano steve at
Fri Apr 3 04:23:39 CEST 2009

On Fri, 03 Apr 2009 08:51:47 +1100, Ben Finney wrote:

> Steven D'Aprano <steve at> writes:
>> I like tab-completion, but I'd rather not be reduced to typing spaces
>> for indents in the interpreter. What do other people do?
> Acknowledge that using U+0009 for indentation is wrong, and use
> beautiful U+0020 always.

Perhaps you missed the "in the interpreter". I'm *not* talking about what 
happens when I hit TAB in my editor, I'm talking about hitting TAB in an 
interactive Python session in a console window. I expect TAB to result in 
an indent level, and backspace to remove that indent level. Tab-
completion clashes with that.

When defining a function in the interactive interpreter:

>>> def spam():
...     return "spam"

I do not wish to type four literal spaces to indent the 'return' line, or 
backspace four times to remove it, but with tab-completion I am forced 
to. I'm used to pressing the TAB key once to get an indent. Within the 
interpreter, I do not care whether it inserts a tab character or four 
spaces or seven formfeed characters, so long as the Python parser 
recognises it as a single indent level and typing backspace once removes 
that indent level.

I'm sorry if this was unclear from my post.

>> The GNU readline library claims that M-tab (which I guess is Alt-tab)
>> will enter a tab character.
> “M-tab” is Emacs-speak for “<Meta> plus <Tab>”. Not all keyboards have
> “Alt”, you see (maybe none, when Emacs first started referring to the
> Meta modifier?).

But on my keyboard, I have no Meta key, I have an Alt key.

> In most terminal programs, you can send “<Alt>-<foo>” also by pressing
> “<Esc>, <foo>” (two separate keystrokes in sequence).
>> Any other suggestions or hints?
> Suck it up and accept the truth! U+0020 is the unambiguous indentation
> character that always does what it should, and U+0009 is a horrible
> mistake which must be suppressed with extreme prejudice. No true
> Pythonista would disagree.

The "No true Scotsman" fallacy.

But regardless of what I use in my source code, I'm purely talking about 
interactive sessions in a console, not an editor.


More information about the Python-list mailing list