Skip to main content

Python Port of John Gruber's titlecase.pl

Project description

https://travis-ci.org/ppannuto/python-titlecase.svg?branch=master https://coveralls.io/repos/github/ppannuto/python-titlecase/badge.svg?branch=master

This filter changes all words to Title Caps, and attempts to be clever about SMALL words like a/an/the in the input.

The list of “SMALL words” which are not capped comes from the New York Times Manual of Style, plus some others like ‘vs’ and ‘v’.

This is a resurrection of Stuart Colville’s titlecase.py, which was in turn a port of John Gruber’s titlecase.pl.

Issues, updates, pull requests, etc should be directed to github.

Installation

The easiest method is to simply use pip:

(sudo) pip install titlecase

Usage

Titlecase provides only one function, simply:

>>> from titlecase import titlecase
>>> titlecase('a thing')
'A Thing'

A callback function may also be supplied, which will be called for every word:

>>> def abbreviations(word, **kwargs):
...   if word.upper() in ('TCP', 'UDP'):
...     return word.upper()
...
>>> titlecase.titlecase('a simple tcp and udp wrapper', callback=abbreviations)
'A Simple TCP and UDP Wrapper'

The callback function is supplied with an all_caps keyword argument, indicating whether the entire line of text was entirely capitalized. Returning None from the callback function will allow titlecase to process the word as normal.

Command Line Usage

Titlecase also provides a command line utility titlecase:

$ titlecase make me a title
Make Me a Title
$ echo "Can pipe and/or whatever else" | titlecase
Can Pipe and/or Whatever Else
# Or read/write files:
$ titlecase -f infile -o outfile

Project details


Download files

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

Source Distribution

titlecase-0.9.0.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

titlecase-0.9.0-py2-none-any.whl (9.2 kB view details)

Uploaded Python 2

File details

Details for the file titlecase-0.9.0.tar.gz.

File metadata

  • Download URL: titlecase-0.9.0.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for titlecase-0.9.0.tar.gz
Algorithm Hash digest
SHA256 12509de9ef64cf75adb8580b7316b07c053432169f49183a406f109951eac0f1
MD5 a9df33be58c2d069ccd3f55f8e3beb65
BLAKE2b-256 4ecc52e00952792e3d6e7f8550608b28d8557e845ed2b0076e4fde1e9b1f31f0

See more details on using hashes here.

File details

Details for the file titlecase-0.9.0-py2-none-any.whl.

File metadata

File hashes

Hashes for titlecase-0.9.0-py2-none-any.whl
Algorithm Hash digest
SHA256 ba4362597c6659d777398bc0a6d2af6fef6dd657bdb4607b5430ced57ced2b69
MD5 e10fa88fee7223dfb774e9a5206f2a83
BLAKE2b-256 a621432ddc9015984b64162b673442c2a5238e5fcf2d8c7daee4d74259113be0

See more details on using hashes here.

Supported by

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