Automate the Boring Stuff with Python

“The best part of programming is the triumph of seeing the machine do something useful. Automate the Boring Stuff with Python frames all of programming as these small triumphs; it makes the boring fun.”
—Hilary Mason, Founder of Fast Forward Labs and Data Scientist in Residence at Accel

Wil Wheaton on reading Automate the Boring Stuff with Python: “I’m having a lot of fun breaking things and then putting them back together, and just remembering the joy of turning a set of instructions into something useful and fun, like I did when I was a kid.”

If you’ve ever spent hours renaming files or updating hundreds of spreadsheet cells, you know how tedious tasks like these can be. But what if you could have your computer do them for you?
In Automate the Boring Stuff with Python, you’ll learn how to use Python to write programs that do in minutes what would take you hours to do by hand—no prior programming experience required. Once you’ve mastered the basics of programming, you’ll create Python programs that effortlessly perform useful and impressive feats of automation to:

Search for text in a file or across multiple files

Create, update, move, and rename files and folders

Search the Web and download online content

Update and format data in Excel spreadsheets of any size

Split, merge, watermark, and encrypt PDFs

Send reminder emails and text notifications

Fill out online forms

Step-by-step instructions walk you through each program, and practice projects at the end of each chapter challenge you to improve those programs and use your newfound skills to automate similar tasks.

Don’t spend your time doing work a well-trained monkey could do. Even if you’ve never written a line of code, you can make your computer do the grunt work. Learn how in Automate the Boring Stuff with Python.

Note: The programs in this book are written to run on Python 3.

Author Bio

Al Sweigart is a software developer and teaches programming to kids and adults. He has written several Python books for beginners, including Hacking Secret Ciphers with Python, Invent Your Own Computer Games with Python, and Making Games with Python & Pygame.

Page 126: In the first paragraph, the second sentence says that “Escaping single and double quotes is optional in raw strings.” It should read “Escaping single and double quotes is optional in multiline strings.”

Page 158: The findall() example has an error. It's marked with #Changed in the code below.

2. When called on a regex that has groups, such as (\d\d\d)-(\d\d\d)-(\d\d\d\d), the method findall() returns a list of tuples of strings (one string for each group), such as [('415', '555', '9999'), ('212', '555', '0000')].

Page 212: The backupToZip.py program has an error. It's marked with #Changed in the code below.

Page 259-60: The example code in the “Filling Out and Submitting Forms” section should be updated to the following, since Gmail has updated their webpage with the username and password fields on separate forms: