Contents in Detail
IMPRACTICAL PYTHON PROJECTS
Playful Programming Activities to Make You Smarter
by Lee Vaughan
San Francisco
IMPRACTICAL PYTHON PROJECTS. Copyright 2019 by Lee Vaughan.
All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher.
ISBN-10: 1-59327-890-X
ISBN-13: 978-1-59327-890-8
Publisher: William Pollock
Production Editor: Janelle Ludowise
Cover Illustration: Josh Ellingson
Interior Design: Octopod Studios
Developmental Editor: Zach Lebowski
Technical Reviewers: Jeremy Kun, Michael Contraveos, and Michele Pratusevich
Copyeditor: Rachel Monaghan
Compositor: David Van Ness
Proofreader: Paula L. Fleming
Indexer: Beth Nauman-Montana
The following images are reproduced with permission:
For information on distribution, translations, or bulk sales, please contact No Starch Press, Inc. directly:
No Starch Press, Inc.
245 8th Street, San Francisco, CA 94103
phone: 1.415.863.9900;
www.nostarch.com
Library of Congress Cataloging-in-Publication Data
Names: Vaughan, Lee, author.
Title: Impractical Python projects : playful programming activities to make
you smarter / Lee Vaughan.
Description: First edition. | San Francisco : No Starch Press, Inc., [2019]
| Includes bibliographical references and index.
Identifiers: LCCN 2018027576 (print) | LCCN 2018029119 (ebook) | ISBN
9781593278915 (epub) | ISBN 1593278918 (epub) | ISBN 9781593278908 (pbk. :
alk. paper) | ISBN 159327890X (pbk. : alk. paper)
Subjects: LCSH: Python (Computer program language)
Classification: LCC QA76.73.P98 (ebook) | LCC QA76.73.P98 V38 2019 (print) |
DDC 005.13/3--dc23
LC record available at https://lccn.loc.gov/2018027576
No Starch Press and the No Starch Press logo are registered trademarks of No Starch Press, Inc. Other product and company names mentioned herein may be the trademarks of their respective owners. Rather than use a trademark symbol with every occurrence of a trademarked name, we are using the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark.
The information in this book is distributed on an As Is basis, without warranty. While every precaution has been taken in the preparation of this work, neither the author nor No Starch Press, Inc. shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in it.
For the Accidental Programmers, the Dedicated Non-Specialists, the Dibblers and Dabblers: all the non-professionals who find themselves writing code every day. May this help you on your way.
About the Author
Lee Vaughan is a geologist with more than 30 years of experience in the petroleum industry. As the Senior Technical Professional for Geological Modeling at a major international oil company, he was involved in the construction and review of computer models; the development, testing, and commercialization of software; and the training of geoscientists and engineers. An advocate for nonprogrammers who must use programming in their careers, he wrote Impractical Python Projects to help self-learners hone their skills with the Python language.
About the Technical Reviewer
Jeremy Kun graduated with his PhD in mathematics from the University of Illinois at Chicago. He writes the blog Math Programming (https://jeremykun.com/) and currently works on datacenter optimization at Google.
BRIEF CONTENTS
ACKNOWLEDGMENTS
Writing a book is a family affair, and I couldnt have succeeded without the support of both my real family and my surrogate family at No Starch Press. First, thanks to my wife, Hannah, and daughters, Sarah and Lora, for their understanding, patience, and endless editing support.
At No Starch, thanks to Bill Pollock and Tyler Ortman for accepting my proposal; Zach Lebowski for making sense of what I was trying to say; Janelle Ludowise for a highly professional job of production editing; Rachel Monaghan and Paula Fleming for taking on the difficult job of copyediting and proofing a technical book; David Van Ness for composition; and Serena Yang and Josh Ellingson for the awesome cover design. Thanks also to my technical reviewers, Jeremy Kun, Michael Contraveos, and Michele Pratusevich, for significantly improving the book with invaluable suggestions and corrections.
External to No Starch, Sarah Vaughan, Eric Evenchick, Xiao-Hui Wu, Brooks Clark, Brian Proett, Brent Francis, and Glenn Krum provided significant technical support.
Finally, thanks to Mark Nathern for introducing me to Python, and to Guido van Rossum for inventing the thing in the first place!
INTRODUCTION
Welcome to Impractical Python Projects! Here, youll use the Python programming language to explore Mars, Jupiter, and the farthest reaches of the galaxy; the souls of poets; the world of high finance; the underworld of espionage and vote tampering; the trickery of game shows; and more. Youll use techniques such as Markov chain analysis to write haiku, Monte Carlo simulation to model financial markets, image stacking to improve your astrophotography, and genetic algorithms to breed an army of gigantic rats, all while gaining experience with modules like pygame , Pylint, pydocstyle, tkinter , python-docx , matplotlib , and pillow . And most of all, youll have fun.
Who This Book Is For
You can think of this as your second Python book. Its designed to follow and complement either a complete beginners book or an introductory class. Youll be able to continue self-training using a project-based approach, without wasting your money or shelf space on a thorough rehashing of concepts youve already learned. But dont worry, I wont leave you hanging; all the code is annotated and explained.
These projects are for anyone who wants to use programming to conduct experiments, test theories, simulate nature, or just have fun. This includes people who use programming as part of their jobs (like scientists and engineers) but who arent programmers per se, as well as those I call the determined non-specialistsdilettantes and dabblers who enjoy programming problems as a fun pastime. If youve wanted to toy with the concepts presented here but found starting potentially complicated projects from scratch too daunting or time-consuming, this book is for you.
Whats in This Book
As you work through the projects, youll increase your knowledge of useful Python libraries and modules; learn more shortcuts, built-in functions, and helpful techniques; and practice designing, testing, and optimizing programs. Additionally, youll be able to relate what youre doing to real-world applications, datasets, and issues.
To quote Ralph Waldo Emerson, Nothing great was ever achieved without enthusiasm. This includes the learning experience. The ultimate goal of this book is to spark your imagination and lead you to develop interesting projects of your own. Dont worry if they seem too ambitious at first; a little diligence and a lot of googling can work miraclesand faster than you think.