Poetry with Python 001: Cruelty

In Reading & Writing Electronic Text, we’ll be writing Python scripts that take text as input, and output poetry.

I searched Project Gutenberg for ‘Manners’ which led me to two public domain books. First, I found Manners and Rules of Good Society (Or Solecisms To Be Avoided), by a Member of the Aristocracy, 1916. I also found Military Manners and Customs by James Anson Farrer, 1885.

I began trying to figure out what words appear a lot, by only printing lines that contained certain words or character strings using line.find(“____”);

Decontextualizing “cruelty” from Military Manners and Customs produced interesting results: cruelty4.txt

But I wanted to incorporate other words, so I created sets for interesting characters that kept popping up like “scurvy” “men” or “man” and “Chr.” Then I wanted to randomize their order, and realized I had to use list() instead of set() and imported random. I further subdivided the Cruelty set into long and short lines to giv control over the rhythm/pacing. I created an order for the random.choice()’s so that the poem, and I preset the first and last lines to  make it feel more like a composition.

Here’s the Python script: cruelty6_fin.py

Here’s the resulting poem: cruelty6.txt*

*The earlier version at the top is actually my favorite.

Leave a Reply

Your email address will not be published.