ebook img

Daniel Arbuckle's mastering Python: build powerful Python applications PDF

266 Pages·2017·8.244 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Daniel Arbuckle's mastering Python: build powerful Python applications

Daniel Arbuckle's Mastering Python (cid:35)(cid:86)(cid:74)(cid:77)(cid:69)(cid:2)(cid:81)(cid:80)(cid:88)(cid:70)(cid:83)(cid:71)(cid:86)(cid:77)(cid:2)(cid:49)(cid:90)(cid:85)(cid:73)(cid:80)(cid:79)(cid:2)(cid:66)(cid:81)(cid:81)(cid:77)(cid:74)(cid:68)(cid:66)(cid:85)(cid:74)(cid:80)(cid:79)(cid:84) Daniel Arbuckle BIRMINGHAM - MUMBAI Daniel Arbuckle's Mastering Python Copyright © 2017 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, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be 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. First published: June 2017 Production reference: 1300617 (cid:49)(cid:86)(cid:67)(cid:77)(cid:74)(cid:84)(cid:73)(cid:70)(cid:69)(cid:2)(cid:67)(cid:90)(cid:2)(cid:49)(cid:66)(cid:68)(cid:76)(cid:85)(cid:2)(cid:49)(cid:86)(cid:67)(cid:77)(cid:74)(cid:84)(cid:73)(cid:74)(cid:79)(cid:72)(cid:2)(cid:45)(cid:85)(cid:69)(cid:16) (cid:45)(cid:74)(cid:87)(cid:70)(cid:83)(cid:90)(cid:2)(cid:49)(cid:77)(cid:66)(cid:68)(cid:70) (cid:21)(cid:23)(cid:2)(cid:45)(cid:74)(cid:87)(cid:70)(cid:83)(cid:90)(cid:2)(cid:52)(cid:85)(cid:83)(cid:70)(cid:70)(cid:85) (cid:35)(cid:74)(cid:83)(cid:78)(cid:74)(cid:79)(cid:72)(cid:73)(cid:66)(cid:78) (cid:35)(cid:21)(cid:2)(cid:20)(cid:49)(cid:35)(cid:14)(cid:2)(cid:54)(cid:44)(cid:16) ISBN 978-1-78728-369-5 Credits Author Copy Editor Daniel Arbuckle Tom Jacob Acquisition Editor Project Coordinator Ben Renow-Clarke Suzanne Coutinho Content Development Editor Proofreader Monika Sangwan Safis Editing Technical Editor Indexer Devesh Chugh Aishwarya Gangawane Graphics Production Coordinator Kirk D'Penha Arvindkumar Gupta About the Author Daniel Arbuckle gained his PhD in Computer Science from the University of Southern California. He has published numerous papers along with several books and video courses, and he is both a teacher of computer science and a professional programmer. www.PacktPub.com For support files and downloads related to your book, please visit (cid:88)(cid:88)(cid:88)(cid:16)(cid:49)(cid:66)(cid:68)(cid:76)(cid:85)(cid:49)(cid:86)(cid:67)(cid:16)(cid:68)(cid:80)(cid:78). 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 (cid:88)(cid:88)(cid:88)(cid:16)(cid:49)(cid:66)(cid:68)(cid:76)(cid:85)(cid:49)(cid:86)(cid:67)(cid:16)(cid:68)(cid:80)(cid:78)and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at (cid:84)(cid:70)(cid:83)(cid:87)(cid:74)(cid:68)(cid:70)(cid:33)(cid:81)(cid:66)(cid:68)(cid:76)(cid:85)(cid:81)(cid:86)(cid:67)(cid:16)(cid:68)(cid:80)(cid:78) for more details. At (cid:88)(cid:88)(cid:88)(cid:16)(cid:49)(cid:66)(cid:68)(cid:76)(cid:85)(cid:49)(cid:86)(cid:67)(cid:16)(cid:68)(cid:80)(cid:78), 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. (cid:73)(cid:85)(cid:85)(cid:81)(cid:84)(cid:28)(cid:17)(cid:17)(cid:88)(cid:88)(cid:88)(cid:16)(cid:81)(cid:66)(cid:68)(cid:76)(cid:85)(cid:81)(cid:86)(cid:67)(cid:16)(cid:68)(cid:80)(cid:78)(cid:17)(cid:78)(cid:66)(cid:81)(cid:85) (cid:2) (cid:2) (cid:2) (cid:2) (cid:2) (cid:2) (cid:2) (cid:2) (cid:2) (cid:2) (cid:2) (cid:2) (cid:2) (cid:2) (cid:2) (cid:2) (cid:2) (cid:2) (cid:2) (cid:2) (cid:2) (cid:2) (cid:2) (cid:2) Get the most in-demand software skills with Mapt. Mapt gives you full access to all Packt books and video courses, as well as industry-leading tools to help you plan your personal development and advance your career. Why subscribe? Fully searchable across every book published by Packt Copy and paste, print, and bookmark content On demand and accessible via a web browser Customer Feedback Thanks for purchasing this Packt book. At Packt, quality is at the heart of our editorial process. To help us improve, please leave us an honest review on this book's Amazon page at (cid:88)(cid:88)(cid:88)(cid:16)(cid:66)(cid:78)(cid:66)(cid:91)(cid:80)(cid:79)(cid:16)(cid:68)(cid:80)(cid:78)(cid:17)(cid:69)(cid:81)(cid:17)(cid:19)(cid:25)(cid:26)(cid:25)(cid:20)(cid:26)(cid:21)(cid:24)(cid:27)(cid:18). If you'd like to join our team of regular reviewers, you can email us at (cid:68)(cid:86)(cid:84)(cid:85)(cid:80)(cid:78)(cid:70)(cid:83)(cid:83)(cid:70)(cid:87)(cid:74)(cid:70)(cid:88)(cid:84)(cid:33)(cid:81)(cid:66)(cid:68)(cid:76)(cid:85)(cid:81)(cid:86)(cid:67)(cid:16)(cid:68)(cid:80)(cid:78). We award our regular reviewers with free eBooks and videos in exchange for their valuable feedback. Help us be relentless in improving our products! Table of Contents Preface 1 Chapter 1: Python Primer 6 Python basic syntax and block structure 6 Basic building blocks 8 Functions 8 Variables 10 Expressions 11 Classes 12 Flow control statements 13 Indentation 14 Python's built-in data structures and comprehensions 15 Dictionaries 15 List 16 Tuple 17 Set 18 Comprehension 19 First-class functions and classes 20 The defaultdict class 22 Attributes 23 The standard library 24 Different types of packages 24 What's new in modern Python 26 The changes in the syntactic 27 Changes in packages 28 Other changes in Python packages 29 Summary 30 Chapter 2: Setting Up 31 Downloading and installing Python 31 Choosing a suitable version 32 Installing Python 32 Using the command line and the interactive shell 34 Opening a command-line window 34 Python interactive shell 35 Installing packages with pip 38 The pip tool for packages 38 Managing installed packages 39 Finding packages in the Python Package Index 42 Using keywords 42 Using Package Index 42 Searching the Package Index with pip 43 Legalities and licenses of the Python Package Index 43 Summary 44 Chapter 3: Making a Package 45 Creating an empty package 45 Turning a regular folder into a package 46 Importing all package modules 47 Adding modules to the package 49 Module loading with namespace packages 50 The Package structure and interface 51 Accessing code from other modules 53 Importing a cyclic dependency 54 Resolving attribute errors raised due to cyclic dependencies 55 Adding static data files to the package 56 Summary 57 Chapter 4: Basic Best Practices 58 PEP 8 and writing readable code 59 PEP 8 — guidelines for Python code 59 Code indentation 60 Formatting recommendations 61 Naming conventions 63 Using version control 63 Initializing Git 64 Committing the changes in Git 64 Undoing the changes 65 Branches 66 Merging codes 68 The mergetool command 69 The pull command 70 Using venv to create a stable and isolated work area 70 Creating a virtual environment 71 Activating a virtual environment 71 pip in virtual environments 72 Getting the most out of docstrings 73 PEP 257 and docutils 73 [ ii ] Sphinx 74 Turning docstrings into HTML 76 Using doctest to test documentation examples 80 Testing examples using doctest 81 What it means when a code example fails 82 Summary 82 Chapter 5: Making a Command-Line Utility 83 Making a package executable via Python -m 84 Pipeline program 85 Handling command-line arguments with argparse 87 Creating an ArgumentParser object 87 Setting the name of argument 88 nargs 90 Python tools to interact with the user 92 Python's built-in functions - print and input 92 The getpass package 93 The pprint package 93 The cmd class 94 The Pipeline user interface 96 Executing other programs with subprocess 98 Subprocess and its variants 98 Using the Popen subprocess 101 The PIPE constant 101 The wait method 102 Finishing up our code example 103 Setting up a shell script or batch file to launch the program 104 Creating launches for our program 104 Summary 105 Chapter 6: Parallel Processing 106 Using the concurrent.futures package 106 The concurrent.futures module 108 Calling ProcessPoolExecutor 109 Using the map method 111 Using the submit method 111 The done and result methods 113 The wait and as_completed functions 115 The add done callback function 116 The cancel method 116 Using the multiprocessing packages 117 Process class in the multiprocessing module 118 Queues 119 [ iii ]

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.