Skip to main content

Incorporate long strings painlessly, beautifully into Python code.

Project description

paragraphs

Incorporate long strings painlessly, beautifully into Python code.

Examples

Easily edited, gq-able, fill-paragraph-able, comprehensive error messages.

from paragraphs import par

class SuddenDeathError(Exception):
    def __init__(self, cause: str) -> None:
        self.cause = cause

    def __str__(self):
        return par(
            f"""
            Y - e - e - e - es, Lord love you! Why should she die of
            {self.cause}? She come through diphtheria right enough the year
            before.I saw her with my own eyes.Fairly blue with it, she was.They
            all thought she was dead; but my father he kept ladling gin down
            her throat til she came to so sudden that she bit the bowl off the
            spoon. 

            What call would a woman with that strength in her have to die of
            {self.cause}?  What become of her new straw hat that should have
            come to me? Somebody pinched it; and what I say is, them as pinched
            it done her in."""
        )

raise SuddenDeathError("influenza")

Nicely-formatted long string data. Spoilers for some old novels here, but these ARE the original titles.

author2titles = {
    "Samuel Penhallow": [
        par(
            """
            The history of the wars of New-England with the Eastern Indians;
            or, a narrative of their continued perfidy and cruelty, from the
            10th of August, 1703, to the peace renewed 13th of July, 1713. And
            from the 25th of July, 1722, to their submission 15th December,
            1725, which was ratified August 5th, 1726"""
        )
    ],
    "Daniel Defoe": [
        par(
            """
            The Life and Strange Surprizing Adventures of Robinson Crusoe, Of
            York, Mariner: Who lived Eight and Twenty Years, all alone in an
            un-inhabited Island on the Coast of America, near the Mouth of the
            Great River of Oroonoque; Having been cast on Shore by Shipwreck,
            wherein all the Men perished but himself. With An Account how he
            was at last as strangely deliver'd by Pyrates"""
        ),
        par(
            """The Fortunes and Misfortunes of the Famous Moll Flanders Who was
            born in Newgate, and during a life of continu’d Variety for
            Threescore Years, besides her Childhood, was Twelve Years a Whore,
            five times a Wife (whereof once to her brother) Twelve Years a
            Thief, Eight Years a Transported Felon in Virginia, at last grew
            Rich, liv’d Honest and died a Penitent"""
        ),
    ],
}

Installation

pip install paragraphs

Use

from paragraphs import par

PARAGRAPH = par("""Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed
    do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
    minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex
    ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate
    velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat
    cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id
    est laborum.""")

# the above is equivalent to

PARAGRAPH = (
    "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod"
    " tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim"
    " veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea"
    " commodo consequat. Duis aute irure dolor in reprehenderit in voluptate"
    " velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint"
    " occaecat cupidatat non proident, sunt in culpa qui officia deserunt"
    " mollit anim id est laborum.")

Features

Joins lines. Removes indentation and leading whitespace.

from paragraphs import par

par('''
    Lorem ipsum dolor
    sit amet,'''
)

# yields
Lorem ipsum dolor sit amet,

Separates paragraphs with double newline ('\n\n').

from paragraphs import par

par '''
    Lorem ipsum dolor
    sit amet,

    consectetur
    adipiscing
    elit'''

# yields
Lorem ipsum dolor sit amet,
<blankline>
consectetur adipiscing elit

Retains one trailing newline (if present).

>>> par('''retains one trailing newline
... ''')
retains one trailing newline
<blankline>

>>> par('''no trailing newline''')
no trailing newline

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

docx2python-1.0.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

docx2python-1.0-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file docx2python-1.0.tar.gz.

File metadata

  • Download URL: docx2python-1.0.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3

File hashes

Hashes for docx2python-1.0.tar.gz
Algorithm Hash digest
SHA256 c15cf8301476ca6f797d67a8e3644e3157486c9474e1d2d1ae483c70af929bd6
MD5 055b16775b7e71b659b48cc4c9dbeb14
BLAKE2b-256 2b2f7293aae39f88cfb7364787cebe3026b3dcd593741c5cab5a7564a803100d

See more details on using hashes here.

File details

Details for the file docx2python-1.0-py3-none-any.whl.

File metadata

  • Download URL: docx2python-1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3

File hashes

Hashes for docx2python-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cd95a73d7d00bc232a287d328e52df23aff1ec0b10ec3992f1d8a7d57b50a00d
MD5 8ae62f344195dde659bd2d8c5be1d6ae
BLAKE2b-256 75192b018c4f48f3b47242460cead746fa9aef01a9f74f0e6b777cdb867f3640

See more details on using hashes here.

Supported by

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