Types
Types#
The wolpie.types package provides type-safe utilities for string manipulation and truncation.
Functions#
pretty_str#
This function was inspired by Python's built-in textwrap.shorten but offers improved pretty string truncation capabilities.
but this is 8 long. So it is shorter than the specified width of 10, but that's not what I want.
I want it to be exactly 10 long, including the placeholder. So I want:
This is what inspired the pretty_str function and later the TStr class.
Classes#
TStr#
I liked the idea of pretty string truncation so much that I wanted to implement it as a class that would automatically truncate itself when it exceeds a specified length.
Why would it be better?
Instead of having to call a function every time you want to truncate a string, you can just use the TStr class and it will take care of it for you.
It's the difference between:
s = "Hello world!"
s += " Adding more text to make it even longer."
s = pretty_str(s, max_length=10)
print(s) # Output: 'Hello w...'
and