textwrap can format paragraphs of text to fit a given screen width
12345678910
>>>importtextwrap>>>doc="""The wrap() method is just like fill() except that it returns... a list of strings instead of one big string with newlines to separate... the wrapped lines."""...>>>print(textwrap.fill(doc,width=40))Thewrap()methodisjustlikefill()exceptthatitreturnsalistofstringsinsteadofonebigstringwithnewlinestoseparatethewrappedlines.
Templating
string module includes a Template class to allow users customize
The format uses placeholder names formed by $ valid Python identifier
1234
>>>fromstringimportTemplate>>>t=Template('${village}folk send $$10 to $cause.')>>>t.substitute(village='Nottingham',cause='the ditch fund')'Nottinghamfolk send $10 to the ditch fund.'
substitute() method raises a KeyError, when a placeholder is not supplied. safe_substitute() will leave placeholder unchanged if data is missing.
12345678
>>>t=Template('Return the $item to $owner.')>>>d=dict(item='unladen swallow')>>>t.substitute(d)....KeyError:'owner'>>>t.safe_substitute(d)'Return the unladen swallow to $owner'