print and format on steroids
Project description
It’s been almost fifty years since C introduced printf() and the basic formatted printing of positional parameters. Isn’t it time for an upgrade? You betcha!
say evolves Python’s print statement/function, format function/method, and % string interpolation operator with simpler, higher-level facilities. For example, it provides direct template formatting:
from say import * x, nums, name = 12, list(range(4)), 'Fred' say("There are {x} things.") say("Nums has {len(nums)} items: {nums}") say("Name: {name!r}")
yields:
There are 12 things. Nums has 4 items: [0, 1, 2, 3] Name: 'Fred'
Or instead of printing the string immediately, you want the string itself, the fmt() function is our version of sprintf().:
>>> fmt("{name} has {x} things and {len(nums)} numbers.") 'Fred has 12 things and 4 numbers.'
The more items being printed, and the more complicated the format invocation, the more valuable this simple inline specification becomes.
But as nice as replacing positional templates with inline templates is–a fact finally officially accommodated with formatted string literals of Python 3.6–say does a lot more. It also works in a variety of ways to up-level the output-generation task. For example:
say.title('Discovered') say("Name: {name:style=blue}", indent='+1') say("Age: {age:style=blue}", indent='+1')
Prints a nicely formatted text block, with a proper title and indentation, and just the variable information in blue.
say provides:
DRY, Pythonic, inline string templates that piggyback Python’s well-proven format() method, syntax, and underlying engine.
A single output mechanism that works the same way across Python 2 or Python 3.
A companion fmt() object for string formatting.
Higher-order line formatting such as line numbering, indentation, and line-wrapping built in. You can get substantially better output formatting with almost no additional code.
Convenient methods for common formatting items such as titles, horizontal separators, and vertical whitespace.
Easy styled output, including ANSI colors and user-defined styles and text transforms.
Easy output to one or more files, without additional code or complexity.
Super-duper template/text aggregator objects for easily building, reading, and writing multi-line texts.
Take it for a test drive today! See the full documentation at Read the Docs.
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 Distribution
Built Distribution
File details
Details for the file say-1.6.6.tar.gz
.
File metadata
- Download URL: say-1.6.6.tar.gz
- Upload date:
- Size: 46.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.29.1 CPython/3.7.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a8a8dc85e99f2b1e78e4a6d755f7b555833f41812ba788a4b3c5eb8ad1d03262 |
|
MD5 | 7bae5634761e8eec824a851bc8a99b63 |
|
BLAKE2b-256 | f6b66a5445ca37d13addb30953ee79aea3f3e67e67360460e4d6e6b8235b40ba |
File details
Details for the file say-1.6.6-py3-none-any.whl
.
File metadata
- Download URL: say-1.6.6-py3-none-any.whl
- Upload date:
- Size: 19.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.29.1 CPython/3.7.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1290d85a9807271e1266580bb1b18ed938541f6ea446dd090941ca7255b984b8 |
|
MD5 | 0edb9b9f6167dcb44b50091aface060c |
|
BLAKE2b-256 | 828f6ace10e0e24143dd9e441a7457dc74451202fdecc2b5ae537a9e02e773e2 |