[Python-Dev] Re: re.split on empty patterns

Fredrik Lundh fredrik at pythonware.com
Tue Aug 10 11:00:08 CEST 2004


Tim Peters wrote:

> > Anyway, we therefore can't just make this the default in 2.4.  We
> > could trigger a warning when emptyok is not supplied and a split
> > pattern results in a zero-length match; users could supply
> > emptyok=False to avoid the warning.  Patterns that never have a
> > zero-length match would never get the warning.  2.5 could then set
> > emptyok to True.
> >
> > Note: raising the warning might cause a serious performance hit for
> > patterns that get zero-length matches a lot, which would make 2.4
> > slower in certain cases.
>
> If you don't intend to change the default, there's no problem.  I like
> "no problem".  This isn't so useful so often that it can't afford to
> wait for Python 3 to change.  In the meantime, "emptyok" is an odd
> name since it's always "ok" to have an empty match.  "split0=True"
> reads better to me, since the effect is to split on a 0-length match.
> split_on_empty_match would be too wordy.

the RE module already have an established method for specifying flags,
either with (?x) markers in the pattern strings, or via the "flags" argument
to re.compile and others.

any reason why you cannot use a new standard flag for this purpose?

(e.g. (?e) and re.EMPTY_OK)

adding a flags argument to re.split is less important; if someone really needs
this feature, they can use (?e) or re.compile(..., re.EMPTY_OK).split()

for extra credit, add EMPTY_OK behaviour to find, finditer, and sub/subn.

</F>





More information about the Python-Dev mailing list