Synopses & Reviews
Ever spent way too much time renaming a folder full of files, or updating hundreds of cells in Excel by hand? You might not be a programmer, but even non-programmers can benefit from knowing how to write simple time-saving scripts. Automate the Boring Stuff with Python teaches you just enough Python for you to start automating your own tedious computer tasks.
Starting from zero, author Al Sweigart gets you up and running with the beginner-friendly Python programming language as quickly as possible, without a lot of unnecessary theory. You start with the basics, learning from code examples that are as practical as they are illustrative. Soon you're using powerful pieces of pre-existing code (Python's "modules") to effortlessly perform truly impressive—and useful—feats of scripting prowess. In particular, this book teaches you how to:
- Search for any pattern of text in a file, or across multiple files
- Organize your life (and computer) by creating, updating, moving, and renaming files and folders
- Scrape the web for data and information
- Instantly update Excel spreadsheets of any size
- Automatically send out emails or text messages
- Schedule your computer to perform tasks at regular intervals
It turns out that you don't need to be a programmer to get your computer to work for you.
Automate the Boring Stuff with Python really is the practical programming guide for the rest of us.
Synopsis
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.
About the Author
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.
Table of Contents
; About the Author; About the Tech Reviewer; Acknowledgments; Introduction; Whom Is This Book For?; Conventions; What Is Programming?; About This Book; Downloading and Installing Python; Starting IDLE; How to Find Help; Asking Smart Programming Questions; Summary; Python Programming Basics; Chapter 1: Python Basics; 1.1 Entering Expressions into the Interactive Shell; 1.2 The Integer, Floating-Point, and String Data Types; 1.3 String Concatenation and Replication; 1.4 Storing Values in Variables; 1.5 Your First Program; 1.6 Dissecting Your Program; 1.7 Summary; 1.8 Practice Questions; Chapter 2: Flow Control; 2.1 Boolean Values; 2.2 Comparison Operators; 2.3 Boolean Operators; 2.4 Mixing Boolean and Comparison Operators; 2.5 Elements of Flow Control; 2.6 Program Execution; 2.7 Flow Control Statements; 2.8 Importing Modules; 2.9 Ending a Program Early with sys.exit(); 2.10 Summary; 2.11 Practice Questions; Chapter 3: Functions; 3.1 def Statements with Parameters; 3.2 Return Values and return Statements; 3.3 The None Value; 3.4 Keyword Arguments and print(); 3.5 Local and Global Scope; 3.6 The global Statement; 3.7 Exception Handling; 3.8 A Short Program: Guess the Number; 3.9 Summary; 3.10 Practice Questions; 3.11 Practice Projects; Chapter 4: Lists; 4.1 The List Data Type; 4.2 Working with Lists; 4.3 Augmented Assignment Operators; 4.4 Methods; 4.5 Example Program: Magic 8 Ball with a List; 4.6 List-like Types: Strings and Tuples; 4.7 References; 4.8 Summary; 4.9 Practice Questions; 4.10 Practice Projects; Chapter 5: Dictionaries and Structuring Data; 5.1 The Dictionary Data Type; 5.2 Pretty Printing; 5.3 Using Data Structures to Model Real-World Things; 5.4 Summary; 5.5 Practice Questions; 5.6 Practice Projects; Chapter 6: Manipulating Strings; 6.1 Working with Strings; 6.2 Useful String Methods; 6.3 Project: Password Locker; 6.4 Project: Adding Bullets to Wiki Markup; 6.5 Summary; 6.6 Practice Questions; 6.7 Practice Project; Automating Tasks; Chapter 7: Pattern Matching with Regular Expressions; 7.1 Finding Patterns of Text Without Regular Expressions; 7.2 Finding Patterns of Text with Regular Expressions; 7.3 More Pattern Matching with Regular Expressions; 7.4 Greedy and Nongreedy Matching; 7.5 The findall() Method; 7.6 Character Classes; 7.7 Making Your Own Character Classes; 7.8 The Caret and Dollar Sign Characters; 7.9 The Wildcard Character; 7.10 Review of Regex Symbols; 7.11 Case-Insensitive Matching; 7.12 Substituting Strings with the sub() Method; 7.13 Managing Complex Regexes; 7.14 Combining re.IGNORECASE, re.DOTALL, and re.VERBOSE; 7.15 Project: Phone Number and Email Address Extractor; 7.16 Summary; 7.17 Practice Questions; 7.18 Practice Projects; Chapter 8: Reading and Writing Files; 8.1 Files and File Paths; 8.2 The os.path Module; 8.3 The File Reading/Writing Process; 8.4 Saving Variables with the shelve Module; 8.5 Saving Variables with the pprint.pformat() Function; 8.6 Project: Generating Random Quiz Files; 8.7 Project: Multiclipboard; 8.8 Summary; 8.9 Practice Questions; 8.10 Practice Projects; Chapter 9: Organizing Files; 9.1 The shutil Module; 9.2 Walking a Directory Tree; 9.3 Compressing Files with the zipfile Module; 9.4 Project: Renaming Files with American-Style Dates to European-Style Dates; 9.5 Project: Backing Up a Folder into a ZIP File; 9.6 Summary; 9.7 Practice Questions; 9.8 Practice Projects; Chapter 10: Debugging; 10.1 Raising Exceptions; 10.2 Getting the Traceback as a String; 10.3 Assertions; 10.4 Logging; 10.5 IDLE's Debugger; 10.6 Summary; 10.7 Practice Questions; 10.8 Practice Project; Chapter 11: Web Scraping; 11.1 Project: mapit.py with the webbrowser Module; 11.2 Downloading Files from the Web with the requests Module; 11.3 Saving Downloaded Files to the Hard Drive; 11.4 HTML; 11.5 Parsing HTML with the BeautifulSoup Module; 11.6 Project: "I'm Feeling Lucky" Google Search; 11.7 Project: Downloading All XKCD Comics; 11.8 Controlling the Browser with the selenium Module; 11.9 Summary; 11.10 Practice Questions; 11.11 Practice Projects; Chapter 12: Working with Excel Spreadsheets; 12.1 Excel Documents; 12.2 Installing the openpyxl Module; 12.3 Reading Excel Documents; 12.4 Project: Reading Data from a Spreadsheet; 12.5 Writing Excel Documents; 12.6 Project: Updating a Spreadsheet; 12.7 Setting the Font Style of Cells; 12.8 Font Objects; 12.9 Formulas; 12.10 Adjusting Rows and Columns; 12.11 Charts; 12.12 Summary; 12.13 Practice Questions; 12.14 Practice Projects; Chapter 13: Working with PDF and word Documents; 13.1 PDF Documents; 13.2 Project: Combining Select Pages from Many PDFs; 13.3 Word Documents; 13.4 Summary; 13.5 Practice Questions; 13.6 Practice Projects; Chapter 14: Working with CSV Files and JSON Data; 14.1 The CSV Module; 14.2 Project: Removing the Header from CSV Files; 14.3 JSON and APIs; 14.4 The JSON Module; 14.5 Project: Fetching Current Weather Data; 14.6 Summary; 14.7 Practice Questions; 14.8 Practice Project; Chapter 15: Keeping Time, Scheduling Tasks, and Launching Programs; 15.1 The time Module; 15.2 Rounding Numbers; 15.3 Project: Super Stopwatch; 15.4 The datetime Module; 15.5 Review of Python's Time Functions; 15.6 Multithreading; 15.7 Project: Multithreaded XKCD Downloader; 15.8 Launching Other Programs from Python; 15.9 Project: Simple Countdown Program; 15.10 Summary; 15.11 Practice Questions; 15.12 Practice Projects; Chapter 16: Sending Email and Text Messages; 16.1 SMTP; 16.2 Sending Email; 16.3 IMAP; 16.4 Retrieving and Deleting Emails with IMAP; 16.5 Project: Sending Member Dues Reminder Emails; 16.6 Sending Text Messages with Twilio; 16.7 Project: "Just Text Me" Module; 16.8 Summary; 16.9 Practice Questions; 16.10 Practice Projects; Chapter 17: Manipulating Images; 17.1 Computer Image Fundamentals; 17.2 Manipulating Images with Pillow; 17.3 Project: Adding a Logo; 17.4 Drawing on Images; 17.5 Summary; 17.6 Practice Questions; 17.7 Practice Projects; Chapter 18: Controlling the Keyboard and Mouse with GUI Automation; 18.1 Installing the pyautogui Module; 18.2 Staying on Track; 18.3 Controlling Mouse Movement; 18.4 Project: "Where Is the Mouse Right Now?"; 18.5 Controlling Mouse Interaction; 18.6 Working with the Screen; 18.7 Project: Extending the mouseNow Program; 18.8 Image Recognition; 18.9 Controlling the Keyboard; 18.10 Review of the PyAutoGUI Functions; 18.11 Project: Automatic Form Filler; 18.12 Summary; 18.13 Practice Questions; 18.14 Practice Projects; Installing Third-Party Modules; The pip Tool; Installing Third-Party Modules; Running Programs; Shebang Line; Running Python Programs on Windows; Running Python Programs on OS X and Linux; Running Python Programs with Assertions Disabled; Answers to the Practice Questions; Chapter 1; Chapter 2; Chapter 3; Chapter 4; Chapter 5; Chapter 6; Chapter 7; Chapter 8; Chapter 9; Chapter 10; Chapter 11; Chapter 12; Chapter 13; Chapter 14; Chapter 15; Chapter 16; Chapter 17; Chapter 18; Resources;