re.search when used within an if/else fails

Ian Kelly ian.g.kelly at gmail.com
Thu Nov 29 01:36:35 CET 2012


On Wed, Nov 28, 2012 at 5:20 PM, Dennis Lee Bieber <wlfraed at ix.netcom.com>wrote:

> On 28 Nov 2012 21:39:03 GMT, Steven D'Aprano
> <steve+comp.lang.python at pearwood.info> declaimed the following in
> gmane.comp.python.general:> py> if True:
> > ...     if True: # tab
> > ...         pass  # tab, then four spaces
> > ...         pass  # two spaces, tab, four spaces
> >   File "<stdin>", line 4
> >     pass  # two spaces, tab, four spaces
> >                                        ^
> > TabError: inconsistent use of tabs and spaces in indentation
> >
>
>         Unless there has been a major change in the parser... (I still
> don't
> have Python 3.x installed)
>
>         I believe <tab> is expanded to 8-spaces -- NOT TO NEXT MULTIPLE OF
> 8...
>

Next multiple of 8 is correct, according to the docs:

Tabs are replaced (from left to right) by one to eight spaces such that the
> total number of characters up to and including the replacement is a
> multiple of eight (this is intended to be the same rule as used by Unix).
> The total number of spaces preceding the first non-blank character then
> determines the line’s indentation. Indentation cannot be split over
> multiple physical lines using backslashes; the whitespace up to the first
> backslash determines the indentation.
>

http://docs.python.org/3/reference/lexical_analysis.html#indentation

Testing Steven's formulation with Python 2, I find that it runs without
comment without the -tt option, but it raises the TabError with the -tt
option.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20121128/11882a73/attachment.html>


More information about the Python-list mailing list