Skip to content

lgarswood/python-formatter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

python-formatter

A formatter for paragraphs which stretches each line across the full page-width.

Requirements

This project is compliant with Python3.6+. To install for mac using the brew manager, run:

brew install python3

Run as an application

From the command-line, in the root project directory, run:

python3 app/format.py --paragraph <quoted-paragraph> --page-width <width>

For example, running:

python3 app/format.py --paragraph "This sentence is not terribly large, and should be parsed fine." --page-width 20

Yields the result:

Array [0] = "This sentence is not"
Array [1] = "terribly large,  and"
Array [2] = "should            be"
Array [3] = "parsed         fine."

Formatting errors:

If your page-width is too big for any given word or a word must be placed alone on a line without taking the full width, it will fail. For example, given the command:

python3 app/format.py --paragraph "This is a very big sentence on the subject of the disestablishmentarian movement." --page-width 20

You will receive the error:

Error: "disestablishmentarian" longer than width 20.

Run as a python package

Ensure the root project directory is included in your PYTHON_PATH and use as:

from typing import List
from app import format_utils

formatted_lines: List[str] = format_utils.split_lines(paragraph, width)

Parsing errors in the above example such as those encountered when running from the command-line will raise a format_utils.FormatException.

Running tests

From the root directory, run:

python3 -m unittest tests/test*.py

Notes

  • This does not use any external packages and thus you will find no requirements.txt file and nothing needs to be installed
  • It is best to use double-quotes instead of single-quotes from the command-line in case you use contractions in a paragraph

About

formatter for paragraphs with alignment

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages