speaklater

raw JSON →
1.3 verified Mon Apr 27 auth: no python maintenance

Provides a lazy string class for Python, useful for deferred string evaluation (e.g., with gettext). Current version 1.3, in maintenance mode with infrequent releases.

pip install speaklater
error ImportError: cannot import name 'LazyString' from 'speaklater'
cause Typo: misspelling or wrong capitalization of the class name.
fix
Use correct import: from speaklater import LazyString
error TypeError: lazy_string object is not callable
cause Assuming LazyString instance is callable; it's not, it evaluates on str conversion.
fix
Use str(lazy_string) or lazy_string.__str__() to get the value.
gotcha LazyString objects do not compare equal to plain strings unless explicitly converted. Comparing a LazyString to a string will always be False.
fix Use str(lazy) before comparison.
deprecated This library is in maintenance mode. Consider using the built-in `str` or a PEP 501-compatible lazy string for new projects.
fix Use `speaklater` only for legacy code; prefer modern alternatives.

Creates a lazy string that evaluates the lambda only when converted to string.

from speaklater import LazyString

lazy_hello = LazyString(lambda: 'Hello, World!')
print(str(lazy_hello))  # Output: Hello, World!