Class: TextFormatter | .\imports\TextFormatter.py | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Formats text into columns.Constructor takes a list of dictionaries that each specify the properties for a column. Dictionary entries can be: width the width within which the text will be wrapped alignment left|center|right margin amount of space to prefix in front of column The compose() method takes a list of strings and returns a formatted string consisting of each string wrapped within its respective column. Example:formatter = TextFormatter( ( {'width': 10}, {'width': 12, 'margin': 4}, {'width': 20, 'margin': 8, 'alignment': right}, ) ) print formatter.compose( ( "A rather short paragraph", "Here is a paragraph containing a veryveryverylongwordindeed.", "And now for something on the right-hand side.", ) ) gives:A rather Here is a And now for short paragraph something on the paragraph containing a right-hand side. veryveryvery longwordinde ed.
|