The code for this tutorial can be downloaded here: threadworms.py or from GitHub. This code works with Python 3 or Python 2, and you need Pygame installed as well in order to run it.
Click the animated gif to view a larger version.
This is a tutorial on threads and multithreaded programs in Python, aimed at beginning programmers. It helps if you know the basics of classes (what they are, how you define methods, and that methods always have self as the first parameter, what subclasses (i.e. child classes) are and how a method can be inherited from a parent class, etc.) Here’s a more in-depth classes tutorial.
The example used is a “Nibbles” or “Snake” style clone that has multiple worms running around a grid-like field, with each worm running in a separate thread.
My third book, Hacking Secret Ciphers with Python, is finished. It is free to download under a Creative Commons license, and available for purchase as a physical book on Amazon for $25 (which qualifies it for free shipping). This book is aimed at people who have no experience programming or with cryptography. The book goes through writing Python programs that not only implement several ciphers but also can hack these ciphers.
100% of the proceeds from the book sales will be donated to the Electronic Frontier Foundation, Creative Commons, and The Tor Project.
Each chapter presents a new program and explains how the source code works. At the same time, various ciphers and cryptography concepts are explored. This book covers:
I first started this book two years ago. The Word doc calculates my editing time for the file at 85,860 minutes (not including the time to write and debug the programs). The book is over 400 pages long with over 1700 lines of code written for the programs (not including whitespace and comments).
The book’s website is at http://inventwithpython.com/hacking
Feel free to email me questions or comments at [email protected] or leave a comment below.