Python speed and `pcre'

M.-A. Lemburg mal at lemburg.com
Wed Sep 15 10:41:51 EDT 1999


François Pinard wrote:
> 
> "M.-A. Lemburg" <mal at lemburg.com> writes:
> 
> > [substrings]
> 
> > Note that Python 1.5.2 already support such beasts... albeit rather well
> > hidden (for obvious reasons ;-) and not fully interoperatable yet:
> 
> > >>> s = '12345678901234567890'
> > >>> snippet1 = buffer(s,8,3)
> [...]
> > You can always turn a buffer back into a string using the str()
> > function.
> 
> > Perhaps the string module should be extended to use "s#"
> > more often...
> 
> Hello.  Thanks for the pointer, yet I'm just starting to understand your
> reply, and it may take some while, still.  The manual is very terse about
> the `buffer' function, relating it to `buffer' methods, without explaining
> any further what these are...  Also, I do not understand the "s#" quote.
> Sorry for being a bit opaque, here.  Would someone suggest some magnetic
> reference to me about these, which a beginner could afford to read and
> understand?  I'm not ready yet to dive into the interpreter sources :-).

Sorry, buffer objects are still somewhat fuzzy and undocumented.
All I can refer you to is the source code in Include/bufferobject.h
and Objects/bufferobject.c.

The "s#" quote was meant for experts: it refers to a format
string passed to PyArg_ParserTuple() for converting Python
objects to C data. "s#" tells the function to give back a
char* Pointer and a length integer and to try to use the buffer
interface of the object to fetch these from the object. By
using "s#" you can make your function compatible to all objects
implementing the buffer interface, ie. not only strings but
also memory mapped files, buffers, etc.

Hope that helps at least a bit,
-- 
Marc-Andre Lemburg
______________________________________________________________________
Y2000:                                                   107 days left
Business:                                      http://www.lemburg.com/
Python Pages:                           http://www.lemburg.com/python/






More information about the Python-list mailing list