Automate The Boring Stuff With Python: Practical Programming for Total Beginners



“You’ve just done in two hours what it takes the three of us two days to do.” My college roommate was working at a retail electronics store in the early 2000s. Occasionally, the store would receive a spreadsheet of thousands of product prices from its competitor. A team of three employees would print the spreadsheet onto a thick stack of paper and split it among themselves. For each product price, they would look up their store’s price and note all the products that their competitors sold for less. It usually took a couple of days.
“You know, I could write a program to do that if you have the original file for the printouts,” my roommate told them, when he saw them sitting on the floor with papers scattered and stacked around them.

After a couple of hours, he had a short program that read a competitor’s price from a file, found the product in the store’s database, and noted whether the competitor was cheaper. He was still new to programming, and he spent most of his time looking up documentation in a programming book. The actual program took only a few seconds to run. My roommate and his co-workers took an extra-long lunch that day. This is the power of computer programming. A computer is like a Swiss Army knife that you can configure for countless tasks. Many people spend hours clicking and typing to perform repetitive tasks, unaware that the machine they’re using could do their job in seconds if they gave it the right instructions.

Part I
Chapter 1. Covers expressions, the most basic type of Python instruction, and how to use the Python interactive shell software to experiment with code.
Chapter 2. Explains how to make programs decide which instructions to execute so your code can intelligently respond to different conditions.
Chapter 3. Instructs you on how to define your own functions so that you can organize your code into more manageable chunks.
Chapter 4. Introduces the list data type and explains how to organize data.
Chapter 5. Introduces the dictionary data type and shows you more powerful ways to organize data.
Chapter 6. Covers working with text data (called strings in Python).
Part II
Chapter 7. Covers how Python can manipulate strings and search for text patterns with regular expressions.
Chapter 8. Explains how your programs can read the contents of text files and save information to files on your hard drive.
Chapter 9. Shows how Python can copy, move, rename, and delete large numbers of files much faster than a human user can. It also explains compressing and decompressing files.
Chapter 10. Shows how to use Python’s various bug-finding and bug-fixing tools.
Chapter 11. Shows how to write programs that can automatically download web pages and parse them for information. This is called web scraping.
Chapter 12. Covers programmatically manipulating Excel spreadsheets so that you don’t have to read them. This is helpful when the number of documents you have to analyze is in the hundreds or thousands.
Chapter 13. Covers programmatically reading Word and PDF documents.
Chapter 14. Continues to explain how to programmatically manipulate documents with CSV and JSON files.
Chapter 15. Explains how time and dates are handled by Python programs and how to schedule your computer to perform tasks at certain times. This chapter also shows how your Python programs can launch non-Python programs.
Chapter 16. Explains how to write programs that can send emails and text messages on your behalf.
Chapter 17. Explains how to programmatically manipulate images such as JPEG or PNG files.
Chapter 18. Explains how to programmatically control the mouse and keyboard to automate clicks and keypresses.

Download PDF