[Python-checkins] r46273 - in python/trunk: Doc/lib/libstdtypes.tex Include/unicodeobject.h Lib/test/string_tests.py Objects/stringobject.c Objects/unicodeobject.c

Jim Jewett jimjjewett at gmail.com
Fri May 26 20:16:28 CEST 2006


On 5/26/06, fredrik.lundh <python-checkins at python.org> wrote:
> Author: fredrik.lundh
> Date: Fri May 26 10:54:28 2006
> New Revision: 46273
>
> Modified:
>    python/trunk/Doc/lib/libstdtypes.tex
>    python/trunk/Include/unicodeobject.h
>    python/trunk/Lib/test/string_tests.py
>    python/trunk/Objects/stringobject.c
>    python/trunk/Objects/unicodeobject.c
> Log:
> needforspeed: partition implementation, part two.
>
> feel free to improve the documentation and the docstrings.
>
>
>
> Modified: python/trunk/Doc/lib/libstdtypes.tex
> ==============================================================================
> --- python/trunk/Doc/lib/libstdtypes.tex        (original)
> +++ python/trunk/Doc/lib/libstdtypes.tex        Fri May 26 10:54:28 2006
> @@ -727,6 +727,14 @@
>  \versionchanged[Support for the \var{chars} argument]{2.2.2}
>  \end{methoddesc}
>
> +\begin{methoddesc}[string]{partition}{sep}
> +Splits the string at the \var{sep}, and return a 3-tuple containing
> +the part before the separator, the separator itself, and the part
> +after the separator.  If the separator is not found, return a 3-tuple
> +containing the string itself, followed by two empty strings.
> +\versionadded{2.5}
> +\end{methoddesc}
> +

I think this may be where the string views came in.

Instead of returning a tuple of funny strings, it could return an
instance of a class that knew about views, and held a reference to the
original string.

    p.head (or p[0])
    p.sep (or p[1])
    p.tail (or p[2])

would be properties that created the new string only if/when that
particular attribute was needed.  It probably isn't worth doing until
the compiler can see that p.tail is only used for another partition,
and can then skip creating the intermediate object.

-jJ


More information about the Python-checkins mailing list