Skip to main content
https://img.shields.io/badge/stdlib--only-yes-green.svg https://travis-ci.org/cjrh/cjrh_template.svg?branch=master https://coveralls.io/repos/github/cjrh/cjrh_template/badge.svg?branch=master https://img.shields.io/pypi/pyversions/cjrh_template.svg https://img.shields.io/github/tag/cjrh/cjrh_template.svg https://img.shields.io/badge/install-pip%20install%20cjrh_template-ff69b4.svg https://img.shields.io/pypi/v/cjrh_template.svg https://img.shields.io/badge/calver-YYYY.MM.MINOR-22bfda.svg

cjrh_template

This package offers a very thin subclass of string.Template which adds a few extra features to the standard library class.

NOTE: this package has no dependencies and will therefore not incur an additional 3rd-party dependency cost. This is intentional and will not change.

Get var names in the template

The placeholders() method returns a generator of the variable names inside the template:

# main.py
from cjrh_template import Template
s = '$person1 gave $object to $person2'
tmpl = Template(s)
print(list(tmpl.placeholders()))

Output:

$ python main.py
['person1', 'object', 'person2']

A typical use-case for this is to be able to see a UI with the required parameters for template substitution. Also, note that the method returns a generator that will return the names sequentially in a memory-efficient way.

There is also an allow_repeats parameter to placeholders() that will allow the generator to return even repeated variable names, depending on the sequence in which they’re found in the template. This could be used to generate frequency counts of variable names. Default is False.

Metadata

Release files for cjrh_template 2017.10.18

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cjrh_template 2017.10.18
File Size Uploaded
cjrh_template-2017.10.18.tar.gz 7.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cjrh_template 2017.10.18
File Interpreter ABI Platform
cjrh_template-2017.10.18-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 22.0 kB

Release files / cjrh_template-2017.10.18.tar.gz

Download URL cjrh_template-2017.10.18.tar.gz
Size 7.1 kB
Tags Source
SHA-256 checksum
How to use checksums
6f814bd21e43ba7cd6f7f4f4019939f573701be9873ce44bb76b0772dbe3b27f
BLAKE2b-256 checksum
How to use checksums
66a2b7d25c9f51621ee2de3b33b60ba148f794705aded639399dc9bc19f5b5a6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / cjrh_template-2017.10.18-py2.py3-none-any.whl

Download URL cjrh_template-2017.10.18-py2.py3-none-any.whl
Size 14.9 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
673adcf024189c0f234886c962b3a4b62ff511b3c9ce1adf1e376d586d65e8e2
BLAKE2b-256 checksum
How to use checksums
c372dd1385217ff7102cf5ae25d512bfd4e5078f5db40f956281756aa81867d1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

2017.10.18 This release

2 release files

2017.5.1

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page