Python speed and `pcre'

M.-A. Lemburg mal at lemburg.com
Fri Sep 3 07:53:40 EDT 1999


[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)
>>> print snippet1
901
>>> snippet2 = buffer(s,14,4)
>>> print snippet2
5678
>>> import string
>>> string.join(snippet1,snippet2)
'95678056781'
>>> string.split(snippet2,'6')
['5', '78']
>>> string.join([snippet1,snippet2])
Traceback (innermost last):
  File "<stdin>", line 1, in ?
TypeError: first argument must be sequence of strings

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...

-- 
Marc-Andre Lemburg
______________________________________________________________________
Y2000:                                                   123 days left
Business:                                      http://www.lemburg.com/
Python Pages:                           http://www.lemburg.com/python/






More information about the Python-list mailing list