Skip to content
StringFragment type to represent parts of str objects; used to avoid copying strings during processing
Python
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
.gitignore
LICENSE.txt
MANIFEST.in
README.md
setup.py
strfrag.py
test_strfrag.py

README.md

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]
'o'
>>> 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)
True

Installation

python setup.py install

This installs the modules strfrag and test_strfrag.

Running the tests

Install Twisted, then run trial strfrag

Contributing

Patches and pull requests are welcome.

This coding standard applies: http://ludios.org/coding-standard/ , except don't camel-case anything in strfrag.py.

Something went wrong with that request. Please try again.