Skip to content

On Programming Language: Diving into Python

This week I’m talking about scripted solutions and the power of programming for a writer. I know it might sound intimidating, but learning a programming language isn’t that much harder than learning any other kind language, and in the same way, some are easier than others.

I almost want to say, “Learning Python is like learning Pig Latin,” because the simplicity is almost there, but I don’t want you to take that to mean Python is a silly, hack-y little gimmick. Let’s say Python is more like learning Spanish. It’s nowhere near as challenging as learning a language with a different alphabet or declined nouns, but it’s got enough nuance that you could spend several years studying it on the college level and still have more to learn.

Even so, you could grab a Travel Guide and put in a really thorough weekend studying before a vacation to Mexico, and learn enough of it to get you from here to there in one piece. So start with the conversational stuff, and pick up the rest as you need it.

The Free Guide

I started out with no programming experience — although, as I mentioned yesterday, all my friends were programmers so I had some idea what to expect. Still, all I did was read one short book. Toby recommended it, and he insisted it would teach me everything I needed to know, so I dove right in.

Appropriately enough, the book is called Dive into Python. I started into the first chapter, and it was filled with instructions for installing the Python software. That I understood.

Then I got to chapter 2, when it really started talking programming stuff, and I was lost. Absolutely, completely, bewilderingly lost. Toby had told me this was all I needed to do, though, so I stuck it through. I did my best to interpret all the nonsense the author was throwing at me, and I kept going.

I’ll admit I had to go back and reread a chapter or two later, once I had a better grasp of it all, but that read-through was really everything I needed to know. I’ve been using (and advocating) Python ever since.

Just like everything else in the arts, you’ve got to get your hands dirty before you can really understand it. So don’t just read — practice. Install the software before you’re done with chapter 1, and try your hand at copying out the code he gives you whenever he says to.

Long before you get to the end of the book, you’ll find yourself figuring out how these little snippets of code work. Then you’ll start developing hypotheses and trying out small changes to see if they behave as expected. It’s enlightening when they don’t, and absolutely glorious when they do.

A Sample Script

Of course, the ultimate goal is to be able to make up your own programs. I’ve told you about a couple of mine, but there’s one I made in Python that some of you have been experiencing directly.

I’ve been using AWeber to handle my weekly newsletter for a couple months now, and while their list management is great, their text editor is awful. I also found myself doing the same things again and again, typing the same metadata into all my hyperlinks (with the minor substitution of the article title), and I knew for all the reasons I mentioned that something like that should be automated.

So I started storing just the little bits of text that I needed in a Google Docs Spreadsheet, and wrote a script that could pull a block of text like this

On Friday I talked about respecting your readers, and specifically focused on <a [Friday]>understanding and deliberately crafting your book’s reading experience</a>. When you consider how your story affects your readers (and what they’re offering in exchange for your storytelling), it becomes far easier to stick to some of the core rules of writing.

from the spreadsheet, then read the WordPress posts list to get the link and title like this

<div class=”post_title”>On Writing Rules: Fair Play in Storytelling</div>
<div>on-writing-rules-fair-play-in-storytelling</div>
<div>2</div>
<div>publish</div>
<div>06</div>
<div>08</div>
<div>2010</div>
<div>06</div>
<div>50</div>

and put them together to build a paragraph of HTML that looks like this

On Friday I talked about respecting your readers, and specifically focused on <a href=”https://unstressedsyllables.com/2010/on-writing-rules-fair-play-in-storytelling/” title=”Writing Advice from Aaron Pogue: &quot;On Writing Rules: Fair Play in Storytelling&quot; at Unstressed Syllables” target=”_blank”>understanding and deliberately crafting your book’s reading experience</a>. When you consider how your story affects your readers (and what they’re offering in exchange for your storytelling), it becomes far easier to stick to some of the core rules of writing.

and shows up in the newsletter like this

On Friday I talked about respecting your readers, and specifically focused on understanding and deliberately crafting your book’s reading experience. When you consider how your story affects your readers (and what they’re offering in exchange for your storytelling), it becomes far easier to stick to some of the core rules of writing.

It’s complicated, and I’m working with Sean on redesigning it into something much cleaner, but even in this form it saves me tons of time, every single week.

Writing a Script (TW Exercise)

Newsletterer is a pretty complicated script. I’ve been working with Python for eight years. I’ve written two games, tons of convenience scripts like that, and two significant applications.

I started small, though. You’ve got to. When you start working your way through the book, you’ll be copying scripts directly off the page that do nothing more than print out the words, “Hello, world!”

It’s a start, and eventually all those simple little tools and tricks fall into place, and suddenly you’re making up your own financial software and trying to figure out how to automate your biggest, most obnoxious tasks.

What’s that going to be for you? What could you automate to make your life easier? Tell us in the comments. Someone might already know a product that’ll do it for you. And if not…well, I’ll be happy to help you learn how to make your own!

Comments are closed.