Tabs/spaces for indentation (was Re: re.search when used within an if/else fails)

Chris Angelico rosuav at gmail.com
Wed Nov 28 18:04:55 EST 2012


On Thu, Nov 29, 2012 at 8:39 AM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> Perhaps it would be nice if Python honoured a directive setting indent
> style to spaces or indents, as it honours source code encoding lines:
>
> # -*- indent: <mode> -*-
>
> Where <mode> could be one of:
>
> space[s]        Only accept spaces in indentation
> tab[s]          Only accept tabs in indentation
> mixed           Accept "mixed" tabs and spaces, but only if consistent
>
> with mixed the default for backward compatibility.

I don't know that it needs to be a declaration like that; character
encodings are critical to parsing the file, but
newline-followed-by-tab and newline-followed-by-space are unambiguous.
But it would be of value to have something like that, as editors could
then be configured to respect it - set the editor to turn tab-key into
N spaces but only if "indent tab" is not set, for instance. The
question is, is it worth it? The main value would be when you're
editing someone else's code.

ChrisA



More information about the Python-list mailing list