[Python-ideas] Making (?x) less scary
Ned Batchelder
ned at nedbatchelder.com
Fri Feb 12 16:12:10 EST 2016
On 2/12/16 11:15 AM, Ryan Gonzalez wrote:
> I was reading re's docs and came across this:
>
>
> Note that the (?x) flag changes how the expression is parsed. It
> should be used first in the expression string, or after one or more
> whitespace characters. If there are non-whitespace characters before
> the flag, the results are undefined.
>
>
> Is there a particular reason for this being undefined? It seems kind
> of un-Pythonic to me and more like C/C++. Would it be possible to
> instead throw an exception, e.g. ValueError?
Is there a reason to deal with this case at all? Throwing an exception
means having to add code to detect the condition and raise the exception.
I'd rather see the docs changed to say, "It must be used first in the
string, or after one or more whitespace characters." No mention of what
happens otherwise is needed.
--Ned.
More information about the Python-ideas
mailing list