Automate the Boring Staff with Python


Automate the Boring Stuff with Python by Al Sweigart (No Starch Press) was what had me type my first purposeful programs. The book also made me love No Starch Press.

(The book is so good I actually bought it twice in multiple Humble Bundle sales. And, given there’s a third edition, I might buy it for a third time.)

Kind of Book

The book is designed to have you start programming by doing. The topic of this doing is ‘I will make you program because that will save you time’. In fact, the scripts are short and they soon prove powerfull. While doing that, you’ll also get a crush course into Python.

This perfectly match the subtitle of the book, naming Practical Programming for the Beginner Programmer.

Contents

The structure of the book is simple yet powerfull. Part I will show you some Python fundamentals. Part II is all about developing projects to automate the boring stuff. Should you have issues getting started with Python installation, running modules or other practicalities, you have three Appedixes tackling these issues.

Here the treatment is “systematic but geared to practice”. So we start with names and variables, integers and strings (ch. 1). As soon as ch. 2 we get into flow control, so that we can create loops and evaluate if/then conditions.

Next up are function (ch. 3), so the part of “hey, you can save a lot of time putting all the if then that work in one case generalizing into a function” comes pretty early. Now that you have quite a lot under your belt to automate stuff, there comes a more comprehensive part on lists (ch. 4), dictionaries and data structures (including methods - in ch. 5), a chapter on strings manipulation (ch. 6).

Chapter 7 is all on regular expressions, chapters 8 and 9 are all on files operations and… wait… it is already from 3 chapters that we are in part. II, automating tasks! That’s what it means for a book to have a great flow.

Chapter 10 is all about Debugging. It tells you to handle and raise exception, use at your convenience the trace back error messages (instead of getting crazy at them). Chances are that, if you are reading the book as a complete beginner, you’ll be puzzled. The programs you see in the book are so clear and obvious… why should dyou debug them? Get over that chapter twice and you’ll be thankful to yourself for the extra reading as soon as you start building your programs without Al’s support and guidance.

From here on you are ready to dive into more and more domains where some automation can be helpful: webscraping (ch. 11), Excel, Word, Pdf files and the more esoteric JSON and CSV formats (up to ch. 14).

Chapter 15 will take your time introducing you dates and time objects. For contingent reasons 1970 is going to be a very important year and ‘epoch’ will soon have a different meaning.

The rich menu is complete by a discussion of SMS, emails, images and keyboard and mourse automation.

Style and Exercises (if Any)

Each chapter has a summary and a set of practice questions. Questions in the first part wants you to start make things with the material provided, questions in part II will have you expand on the functionalities of the programs you made, automating even more.

Favourite Pick

You’ll love the projects on PDFs. They’ll bring you infinite merging and cutting in a few lines of code. If you teach, automating the generation of quizzes will be very useful as well.

The chapter on webscraping is quite cool. It actually made me start my “hey, getting google links should be easy” project (it wasn’t).

Extending the Stuff (Prolonging the Magic)

Downloading stuff from the internet is cool. If you love ebooks, Amazon’s Kindlegen tool (https://www.amazon.com/gp/feature.html?ie=UTF8&docId=1000765211) is your new friend. With KindleGen you have a command line tool that converts various inputs into MOBI documents.

You can now build programs such as:

  1. a MOBI converter. It looks for EPUBs documents in a (set of?) folders, and sends the to KindleGen for conversion. (Bonus points for handling the file ops like sending converted files to your device and canceling them after that);
  2. a web scraper that gets some html content you like (e.g. the documentation of a Python library), assembles it into a unique file and builds a digest for you;
  3. a command line tool that turns whatever you assing it into a document you’ll read on your ereader.