Skip to content


Subversion checkout URL

You can clone with
Download ZIP
StringFragment type to represent parts of str objects; used to avoid copying strings during processing
Branch: master
Fetching latest commit...
Cannot retrieve the latest commit at this time.

Strfrag overview

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


Patches and pull requests are welcome.

This coding standard applies: , except don't camel-case anything in

Something went wrong with that request. Please try again.