Doctest is a really clever built-in Python module that allows you to embed automated tests in documentation strings. If you’re somewhat new to Python and that sounds complicated — it isn’t. It is very easy to set up; I will show you how.

A screenshot of a simple Python function, with a working doctest. This function is included as text further down.
A screenshot of a simple Python function, with a working doctest. This function is included as text further down.
A screenshot of a simple Python function, with a working doctest.

How documentation strings work in Python

Let’s say you have a file with a function which adds two numbers together. Such a function obviously isn’t useful, but I’ll use it as a simple example of how we can use to both document and test the function. So here's our file:

In case you’re not familiar with how documentation strings in Python works, I will show you — let’s add some documentation to the function. …


Disclaimer: I understand that languages change, that they always have and always will, and why that’s okay. And do not take this as a screed against the English language in particular; it was the second one Ilearned, and remains my favorite for many endeavors. But Jesus fucking Christ it pisses me off sometimes. So this is my windmill, let me tilt impotently at it.

Image for post
Image for post
Illustration 6 for Miguel de Cervantes’sDon Quixote“ by Gustave Doré, 1863.

“Multiverse”. Just listen to how stupid it sounds.

“Multiverse” is a word that was invented by morons who don’t understand the meaning of the word “universe”. I’ll give you a hint: “universe” means everything. Yeah, that’s right, everything. …


Image for post
Image for post
“man holding black leather wallet” by Artem Bali on Unsplash

I enjoy writing articles on Medium. I also enjoy making money. So when I learned that you can now make money by writing articles on Medium, I thought “Great! Two birds with one stone, and one of the birds is money, let’s do this!”

Why it didn’t work

But it didn’t work out that way. First of all, I don’t have enough reach, because I only have around 100 followers. I realized that was a problem, since I wouldn’t be able to get my member-only stories in front of enough paying members. “But I can fix that,” I thought, “if only I can get my articles published in publications!


Dad, if you don’t stop talking about things from the 1900’s, people are going to think YOU are from the 1900's!

It’s been nine years since my daugter said the above to me at six years old, and I’ve nearly forgiven her by now. I still love her, but this story isn’t about her. No, this story is about my first love, the Commodore 64 — a home computer from the 80’s, which is still the best selling computer of all time. …


Have you heard of the Butterfly effect? In short, it’s the hypothesis that something small and seemingly unimportant can, through an unforseen chain of events, have a massive impact somewhere else. This effect is real; I know, because it’s happened to me. Come with me as I regale you with the tale of two words that forever changed my life for the better.

When I was in college studying computer science in the mid 1990’s, my friends and I spent a considerable amount of time in the school’s computer labs. Home internet was expensive in those days, and after six p.m. we were allowed to play games there. A lot of time was spent advancing through the levels as players on MUDs — the text-based precursors to graphical MMORPGs like World of Warcraft, and conquering space in the team-based Netrek game inspired by Star Trek. And I’m pretty sure we occasionally did some actual school work in between games as well, but I’ll be damned if I remember any of it. Incidentally, I once won the European Netrek League with my team Chainsaw Hamsters, where I played using the name Roadkill Hamster. This was long before anyone had ever heard to word “e-sports”. …


Image for post
Image for post
No Lego knights were injured during the writing of this article. It’s not like they wouldn’t have deserved it, though, especially the guy on the left — he’s a total douchebag.

Procrastination — we’ve all been there. There’s that one (or many!) intimidating task you really should do, but you really don’t want to. So here are some techniques that have helped me overcome this problem in the past.

  1. Plan how to solve it
  2. Divide and Conquer
  3. Work on it for five minutes

I will go into detail about each of them below.

1. Plan how to solve it

I find that in my case, sometimes when I have an important task ahead that I keep putting off, it helps to just think about how to solve it before I start actually working on it. …


In order to get organized and stay productive, we need to do things every day that we don’t necessarily want to do. We have to learn that “needs to do” goes before “want to do”. This is hard. That’s why there’s a gazillion self-help books and websites out there. So now I’m going to once and for all completely solve this problem for all people globally.

Well, perhaps not. But it might be useful for someone besides me, which is why I’m publishing this.

Forget motivation and build good habits instead

A habit is something you just do without really thinking about it. You do it even if you don’t feel motivated to do it, and this is key; do not depend on motivation, because motivation is inherently undependable — you will not always be motivated to do what you need to do. So forget motivation, and form good habits instead. …


Image for post
Image for post
One of the advantages of holding a Shorinji Kempo black belt is that you get to dress like a god damn Jedi master. Photo by my wife.

I’ve been practicing a martial art known as Shorinji Kempo since 2012. Shorinji Kempo puts an unusually heavy emphasis on philosophy, even for a Japanese martial art. At every grading, you have to turn in an essay on a given topic, as part of the exam. This goes even for children, from the age of ten.

I have learned a great many things while practicing Shorinji Kempo, only some of which have to do with the actual fighting. I’m lucky enough to have Anders Pettersson-sensei as my instructor. He’s a 30+ year veteran of Shorinji Kempo, and at Daikenshi 6 Dan (sixth degree black belt!), …


Ever since I started making software for the Internet back in 1995, I’ve been fascinated by chatbots — programs that attempt to chat with humans, as if they too were human. Back in 1995, however, chatbots typically weren’t the conversational kind, they more commonly acted as automated administrators. They were frequently employed on IRC (Internet Relay Chat) to keep channels clean of spammers, and other such tasks. If you’re new to IRC (or haven’t used it in a while), I recommend you read this excellent Medium article by Baseer Hussain to get up and running.

Today, I will show you how to make a simple IRC bot in Python 3, which you can then extend to do whatever you want. I’ve developed and tested it on Linux, but it should run without any major problems on other operating systems as well. …


Image for post
Image for post
Photo by Peter Fogden on Unsplash

We all have hopes and dreams for our lives. Some people want to have a bigger house, some want to get a dream job, and some just want to have a roof over their head. No matter what your goals are, the over-arching method for getting there is the same.

If we simplify things a little, getting to where you want to be in life is a three step process:

  1. Decide where you want to be in life
  2. Make a plan for how to get there
  3. Execute the plan

Yeah, I get it, this isn’t exactly rocket science. It’s kind of obvious. Yet ask yourself — do you have a plan? One that you’re actively working on? No? Then read on, maybe I can help. First I will show you how you can to do it, then I will provide an example. …

About

Christer Enfors

Parent, gamer, professional software development nerd and amateur martial arts nerd. http://operationgyst.com

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store