Writing Poetry in Python

Python has been called a poetic programming language, so I thought why not try writing poetry with it?  This is a bit of a departure, but my background in Art History always helps me look for the artistic applications of what we’re doing at Trinket.  So here’s a generative poem I wrote in Python. Click Run and see what you get:

Each time you run it you’ll get a different poem.  You can edit the lists of words to customize it to be whatever you like.

It’s not an earth-shatteringly great poem.  I do think it helps demonstrate how computation isn’t just for computer science.  To make the poem better, I’d first start by making lists of different verb tenses and types (transitive/intransitive) and split nouns into subjects and objects to allow for more complex sentence construction. As is, the random spacing juxtaposed with a refrain of sorts gives it a nice rhythm when read aloud. But, like all programs, it’s got to start small and simple.

 

Others have done much more interesting things than this with computational poetry .  I first encountered the work of Nick Montfort during a Natural Language Processing class I took in grad school.  His Computational Poems were very inspiring to me.  At the time I was just beginning to teach myself to program and seeing through his work what was possible was incredibly motivating.

 

MIT’s Nick Montfort

At Trinket our mission is to help every teacher teach with hands-on interactive examples in their classroom.  Our first Trinkets all involve Python, but we’re seeing very innovative usage of them in other subjects like Math and Physics.  If you’re an English or Literature teacher and are or want to use Python in your class, please Tweet me– I’d love to hear what you’re doing and help out if I can!

  • damianavila82

    Hey… nice ideas, but there are some missing pieces in the code… cheers.

    • http://coursefork.org/ Elliott Hauser

      Hey there. The trinket above is remixable so if you improve on it and post the link here (or email me at elliott@trinket.io) I’ll be happy to update the post with a thanks/credit to you!