StringFragment type to represent parts of str objects; used to avoid copying strings during processing
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


A strfrag.StringFragment represents part of a str object. This can be used to avoid copying long str objects as you incrementally process them.

>>> from strfrag import StringFragment
>>> sf = StringFragment("hello world", 2, 8)
>>> sf
<StringFragment for 0xf74c5240, pos=2, size=8, represents 'llo worl'>
>>> sf[2]
>>> sf[2:5]
<StringFragment for 0xf74c5240, pos=4, size=3, represents 'o w'>
>>> str(sf)
'llo worl'
>>> sf.as_buffer()
<read-only buffer for 0xf74c5240, size 8, offset 2 at 0xf74c5220>

# StringFragments that represents the same bytes are equal:

>>> StringFragment("hello world", 1, 5) == StringFragment("ello ", 0, 5)


python install

This installs the modules strfrag and test_strfrag.

Running the tests

Install Twisted, then run trial strfrag