Partially lockable strings
Project description
lstr: partially lockable Python strings
lstr
is a Python package for partially lockable strings.
Installation
lstr
requires Python 3.8 or later.
pip install lstr
Examples
Creating an lstr
from lstr import lstr
greeting = lstr("Hello, world!")
print(greeting)
Hello, world!
Getting help with indexes
from lstr import lstr
greeting = lstr("Hello, world!")
print(repr(greeting))
0 1 2 3 4 5 6 7 8 9 10 11 12
H e l l o , w o r l d !
Inserting text
from lstr import lstr
greeting = lstr("Good morning, Bobby!")
greeting.write("Captain ", index=14)
print(greeting)
Good morning, Captain Bobby!
Overwriting text
from lstr import lstr
greeting = lstr("Good morning, Captain Bobby!")
greeting.write("Fleet Admiral", index=14, length=7)
print(greeting)
Good morning, Fleet Admiral Bobby!
Substituting text
from lstr import lstr
greeting = lstr("Good morning, Fleet Admiral Bobby!")
greeting.sub("morning", "evening")
print(greeting)
Good evening, Fleet Admiral Bobby!
Substituting text with a regular expression
from lstr import lstr
greeting = lstr("Good evening, Fleet Admiral Bobby!")
greeting.sub(r"(Fleet Admiral)", r"🎉\g<1>🎉")
print(greeting)
Good evening, 🎉Fleet Admiral🎉 Bobby!
Locking a range
from lstr import lstr
greeting = lstr("Good morning, Fleet Admiral Bobby!")
greeting.lock(index=14, length=13)
greeting.write("Ensign", index=14, length=13)
print(greeting)
Good morning, Fleet Admiral Bobby!
Locking a substitution
from lstr import lstr
greeting = lstr("Good morning, Captain Bobby!")
greeting.sub("Captain", "Fleet Admiral", lock=True)
greeting.sub("Fleet Admiral", "Ensign")
print(greeting)
Good morning, Fleet Admiral Bobby!
Equality
lstr
instances are considered equal only if their string value and locks are identical.
lstr("f", locks=[Lock(index=1, length=2)]) == lstr("f", locks=[Lock(index=1, length=2)])
lstr("f", locks=[Lock(index=1, length=2)]) != lstr("f", locks=[Lock(index=3, length=4)])
lstr
and str
instances are considered equal if the string value is identical, regardless of the locks.
lstr("f") == "f"
lstr("f") != "g"
Thank you! 🎉
My name is Cariad, and I'm an independent freelance DevOps engineer.
I'd love to spend more time working on projects like this, but--as a freelancer--my income is sporadic and I need to chase gigs that pay the rent.
If this project has value to you, please consider ☕️ sponsoring me. Sponsorships grant me time to work on your wants rather than someone else's.
Thank you! ❤️
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
File details
Details for the file lstr-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: lstr-1.0.0-py3-none-any.whl
- Upload date:
- Size: 6.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/54.1.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 522a612629c743608b3e8b2ae9c6b520f06a0ac228989cad7e3de166a861ac8d |
|
MD5 | 7ad05ca16dc8bf20f69cb957badc7b1f |
|
BLAKE2b-256 | b19986749b3aafeac9982df0bf39d6e7bf8393cc586df4c5c5ae6149933af60d |