[Tutor] creating the equivalent of string.strip()

Dave Kuhlman dkuhlman at rexx.com
Tue Oct 2 18:32:47 CEST 2007


On Tue, Oct 02, 2007 at 06:48:13AM -0400, Kent Johnson wrote:
> Christopher Spears wrote:
> > I was looking for the source code for the strip
> > functions at python.org.  I didn't find anything.  Do
> > you or someone else know where the source code is
> > posted?  I tried to find python on my workstation, but
> > I'm not sure where the sys admin installed it.
> 
> The source for the portion of Python written in C is not installed with 
> the regular Python installer on Mac or Windows (don't know about Linux). 
> You can download it here - get the "Python 2.5.1 compressed source tarball":
> http://www.python.org/download/
> 

If you decide to look at the source, look for the strip
function/method in the following files:

    Objects/stringobject.c
    Modules/stropmodule.c

The first contains the implementation of the method on string
objects.  The second is the implementation of the function that you
get by doing "import string".

As an advanced exercise, install Pyrex/Cython, then implement the
strip function using that.

For more on Cython/Pyrex, see: http://wiki.cython.org/. 
Cython/Pyrex is a Python-like language for writing Python C
extensions in a Python-like language. Pyrex/Cython gets you much
closer to C code than Python.

Question: Someday will all the Python built-ins be implemented in
Cython/Pyrex.

Dave


-- 
Dave Kuhlman
http://www.rexx.com/~dkuhlman


More information about the Tutor mailing list