I am new to Python, and I wanted to read an easy book, that would give me a hight level overview of the language and what I can do with it.

Automate the Boring Stuff with Python by Al Sweigart was exactly what I was looking for.

Book Structure

The book starts out a little slow, since Part I covered the Python Programming Basics, with the emphasis on the Basics. I quickly read through it though, because I wanted to familiarize myself with Python syntax, and I am glad that I did. I’ve picked up some nice tips (copy and paste into clipboard, joining strings etc.) in Part I, that I would have missed otherwise.

Part II goes into practical application of the core concepts and it is summarized in the next section. Overall, the book was clearly written by somebody who spent many years working with Python. It read like a collection of useful tips, with most examples being less than 20 lines of code.

Covered Modules

Bellow is the list of modules that author discussed in his book. Knowing what module to use is already half the battle 🙂 You might want to save this list, for the next time you’ll find yourself asking “What module do I use to do X in Python?”

beautifulsoup4 – Parse HTML

copy – Copy and deep copy of objects

csv – Work with CSV files

datetime – Basic date and time types

python-docx – Work with Microsoft Docx files

imapclient – IMAP client library

json – Work with JSON files/data

logging – Control Logging output based on config (i.e. debug vs production mode)

openpyxl – Work with Excel files

os – Operating System interface, change directory etc.

pprint – Pretty Print your data, instead of regular print.

pyautogui – Cross platform GUI automation, control your mouse and keyboard to automate any program

PyPDF2 – Work with PDF files

pyperclip – Copy/Paste to/from your clipboard

pyzmail – Email library for reading, composing, and sending emails

re – Regular Expressions

requests – Make HTTP requests

pillow – Work with images

selenium – Browser automation using Selenium – open web pages, sign in, fill out forms etc.

send2trash – Delete files

shelve – Persist your in memory objects into a file, to load at a later time

shutil – Shell utilities: copy, move etc.

smtplib – SMTP client

subprocess – Spawn new processes

threading – Start new threads

time – Time related functions epoch etc.

traceback – Print stack traces

twilio – Twilio integration for phone calls and SMS

webbrowser – Open web browser and tabs

zipfile – Work with Zip Archives

Examples of Automation

The author takes us through the following areas that can be automated with Python. I am also highlighting some of the examples that stood out for me.

Pattern Matching with Regular Expressions Finding and replacing phone numbers, emails and urls in a range of text files Reading and Writing Files Opening, reading from, and saving data to files Organizing Files Copying, renaming and deleting files

Listing files in folder and all folders inside that folder

Compressing and uncompressing files (i.e. creating ZIP files) Debugging Web Scraping Scrape and parse HTML to extract all images from various web pages

Use a Selenium module to automate opening browsers and navigating and interacting with web pages (i.e. sign in, fill out a form) Working with Excel Spreadsheets Opening, reading data from and writing data to Excel files Working with PDF and Word Documents Extracting text from PDFs

Combining multiple PDF files into one

Creating and styling a word document Working with CSV Files and JSON Data Simple example of reading, parsing and saving the data Keeping Time, Scheduling Tasks, and Launching Programs Time tracking Modules

Example of a Multithreaded program to fetch data from various pages on a website Sending Email and Text Messages Connecting to email server to send and receive Messages

Using Twilio Module/API to send text messages to yourself to notify when a long running process is done Manipulating Images Adding a logo to each image in a folder Controlling the Keyboard and Mouse with GUI Automation Writing code to click around your desktop and send keyboard key presses, allowing to automate virtually any software that your computer can run.

Summary

I though that Automate the Boring Stuff with Python by Al Sweigart was a great read. Not only did the book provide an easy introduction to the Python programming language, but also opened my eyes (as mostly a web developer) to different kinds of tasks that I can easily automated with Python.