Skip to main content

print and format on steroids

Project description

PyPI Package latest release PyPI Package monthly downloads Supported versions Supported implementations Wheel packaging support Test line coverage

It’s been forty five 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, 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.

http://content.screencast.com/users/jonathaneunice/folders/Jing/media/81bf4738-c875-4998-82ac-a91d211d000b/00000745.png

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

say-1.4.1.zip (61.6 kB view details)

Uploaded Source

say-1.4.1.tar.gz (45.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

say-1.4.1-py2.py3-none-any.whl (22.3 kB view details)

Uploaded Python 2Python 3

File details

Details for the file say-1.4.1.zip.

File metadata

  • Download URL: say-1.4.1.zip
  • Upload date:
  • Size: 61.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for say-1.4.1.zip
Algorithm Hash digest
SHA256 2960d0ec8abaf2e64d750277ee6b071ed77e4169c0b0e01949fc202c8d84cbeb
MD5 e7b85f3df4d5bf8855171f7b6e259658
BLAKE2b-256 8bea1ccb4cc33491194eb71ec2df40b9f76ab3d90ecb547104520938d0731dd6

See more details on using hashes here.

File details

Details for the file say-1.4.1.tar.gz.

File metadata

  • Download URL: say-1.4.1.tar.gz
  • Upload date:
  • Size: 45.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for say-1.4.1.tar.gz
Algorithm Hash digest
SHA256 f2da674a5a409b00e493a6a5c725796a681accad14351177209d8bf66c0246d4
MD5 ffefdf4d0e4eae61c36b79605feab45b
BLAKE2b-256 d2caf585b2bd2fde0378de8df0801c3ad5845875477ebd57584ec3bd04ab5a84

See more details on using hashes here.

File details

Details for the file say-1.4.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for say-1.4.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 20f658e1b3ba337ab09f38485219a9ff33f9ee98c41aefb912a5fae7e28d4374
MD5 266c0c389cdca646f04f3cc44c3e0fd2
BLAKE2b-256 0227338f6854fc4d99d08023384145d8bfce9da17d3aff8c28b3874d81474783

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page