Modern Python Standard Library Cookbook
Over 100 recipes to fully leverage the features of the standard library in Python
Alessandro Molina
BIRMINGHAM - MUMBAI
Modern Python Standard Library Cookbook
Copyright 2018 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author(s), nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
Commissioning Editor: Aaron Lazar
Acquisition Editor: Chaitanya Nair
Content Development Editor: Rohit Singh
Technical Editor: Romy Dias
Copy Editor: Safis Editing
Project Coordinator: Vaidehi Sawant
Proofreader: Safis Editing
Indexer: Mariammal Chettiyar
Graphics: Jason Monteiro
Production Coordinator: Deepika Naik
First published: August 2018
Production reference: 1300818
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham
B3 2PB, UK.
ISBN 978-1-78883-082-9
www.packtpub.com
mapt.io
Mapt is an online digital library that gives you full access to over 5,000 books and videos, as well as industry leading tools to help you plan your personal development and advance your career. For more information, please visit our website.
Why subscribe?
Spend less time learning and more time coding with practical eBooks and videos from over 4,000 industry professionals
Improve your learning with Skill Plans built especially for you
Get a free eBook or video every month
Mapt is fully searchable
Copy and paste, print, and bookmark content
PacktPub.com
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at service@packtpub.com for more details.
At www.PacktPub.com , you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks.
Contributors
About the author
Alessandro Molina has been a Python developer since 2001, and has always been interested in Python as a web development platform. He has worked as a CTO and a team leader of Python teams for the past 10 years and is currently the core developer of the TurboGears2 web framework and maintainer of Beaker Caching/Session framework. He authored the DEPOT file storage framework and the DukPy JavaScript interpreter for Python and has collaborated with various Python projects related to web development, such as FormEncode, ToscaWidgets, and the Ming MongoDB ORM.
To Stefania for constantly supporting me through the late nights and pushing me to write one paragraph when I felt like slacking, without her continuous support I would have never finished this book.
To the Python community, for being such a great and positive environment where discussions can flourish within respect for each other and to all Python conferences organizers for giving us a great chance to discuss our ideas with other great developers in front of a cold beer.
About the reviewer
Simone Marzola is a software engineer and technical lead with 10 years of experience. He is passionate about Python and machine learning, which lead him to be an active contributor in open source communities such as Mozilla Services and Pylons Project, and involved in European conferences as a speaker. Simone has been a lecturer on the Big Dive data science and machine learning course. He is currently a CTO and Scrum Master at Oval Money.
Packt is searching for authors like you
If you're interested in becoming an author for Packt, please visit authors.packtpub.com and apply today. We have worked with thousands of developers and tech professionals, just like you, to help them share their insight with the global tech community. You can make a general application, apply for a specific hot topic that we are recruiting an author for, or submit your own idea.
Preface
Python is a very powerful and widespread language, with a fully-featured standard library. It's said to come with batteries included, which means that most of what you will have to do will be available in the standard library.
Such a big set of functions might make developers feel lost, and it's not always clear which of the available tools are the best for solving a specific task. For many of these tasks, external libraries will also be available that you can install to solve the same problem. So, you might not only find yourself wondering which class or function to use from all the features provided by the standard library, but you will also wonder when it's best to switch to an external library to achieve your goals.
This book tries to provide a general overview of the tools available in the Python standard library to solve many common tasks and recipes to leverage those tools to achieve specific results. For cases where the solution based on the standard library might get too complex or limited, it will also try to suggest tools out of the standard library that can help you do the next step.
Who this book is for
This book is well suited for developers who want to write expressive, highly responsive, manageable, scalable, and resilient code in Python. Prior programming knowledge of Python is expected.
What this book covers
, Containers and Data Structures, covers less obvious cases of data structures and containers provided by the standard library. While more basic containers such as list and dict are taken for granted, the chapter will dive into less common containers and more advanced usages of the built-in containers.
, Text Management, covers text manipulation, string comparison, matching, and the most common needs when formatting output for text-based software.
, Command Line, covers how to write terminal/shell based software, parsing arguments, writing interactive shells, and implement logging.
Next page