Pro-Python-Best-Practices-Debugging-Testing-and-Maintenance.pdf.pdf

所需积分/C币:9 2019-09-15 23:08:49 5.46MB PDF
52
收藏 收藏
举报

Pro-Python-Best-Practices-Debugging-Testing-and-Maintenance.pdf
Pro Python Best Practices: Debugging, Testing and maintenance Kristian rother Berlin, Germany ISBN-13(pbk:978-1-4842-22409 ISBN-13( (electronic:978-1-4842-2241-6 DOI10.1007/978-1-48422241-6 Library of Congress Control Number: 2017936044 Copyright o 2017 by Kristian Rother This work is subject to copyright All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse ofillustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed. Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are notidentified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made The publisher makes no warranty, express or implied with respect to the material contained herein Managing director: Welmoed Spahr Editorial director: Todd green Acquisitions Editor Steve anglin Development Editor Matthew Moodie Technical reviewer: michael thomas Coordinating Editor: Mark Powers Copy Editor Brendan Frost Compositor: SPi Global Indexer: SPi Global Cover image designed by Freepik Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax(201)348-4505, e-mail orders-ny@springer-sbm.com,orvisitwww.springeronline.comApressMedia,LlcisaCaliforniaLlc and the sole member(owner)is Springer Science Business Media Finance Inc(SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation Forinformationontranslationspleasee-mailrights@apress.com,orvisithttp://www.apress.com/ rights-permissions e press titles may be purchased in bulk for academic, corporate, or promotional use e Book versions and censes are also available for most titles for more information reference our print and e book bulk sales web pageatwww.apress.com/bulk-sales Any source code or other supplementary material referenced by the author in this book is available to readersonGithubviathebooksproductpagelocatedatwww.apress.com/9781484222409.Formore detailedinformationpleasevisithttp://www.aprEss.com/source-code Printed on acid-free paper To my pe Contents at a glance About the author About the technical reviewer Acknowledgments,,,,,,,,围算,,,Xv Preface ■凵■■■■■■■■■■■■■■■■■■■■■■■■■■■■口■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ Chapter 1: Introduction mmamammammaammmammmmmammmmammaammam 1 Part s: Debugging,,…,,,,…,,,,,,,,:11 Chapter 2: Exceptions in Python ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 13 Chapter 3: Semantic Errors in Python 27 Chapter 4: Debugging with the Scientific Method ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 43 Chapter 5: Debugging with print Statements ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 55 Chapter 6: Debugging with Introspection Functions mmmmmmmmmammmmmmam, 67 Chapter 7: Using an Interactive Debugger maammmmnmaammmmmmaa 85 Part l: Automated Testing,…,,…,,,,票,101 Chapter 8: Writing Automated Tests ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 103 Chapter 9: Organizing Test Data ■■■■■■■■■■■■■■■■■口■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■口■■■■■■■■■■■■ 117 Chapter 10: Writing a Test Suite ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 129 Chapter 11: Testing Best Practices. 145 CONTENTS AT A GLANC Part l maintenance ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 159 Chapter 12: Version Controlammmmmmmmmmmmmmmm 161 Chapter 13: Setting Up a Python Project mmn 181 Chapter 14: Cleaning Up code Ea w195 Chapter 15: Decomposing Programming Tasks. a213 Chapter 16: Static Typing in Python m mmn 231 Chapter 17: Documentation 245 Index umm 261 Contents About the author About the technical reviewer Acknowledgments,,,,,,,,围算,,,Xv Preface ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■口■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ Chapter1: Introduction,,,…,…,,,…,…,,,…,1 A Lesson in Humility DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD The case for best practices in python DD■DDD■DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD The origin of Best Practices Hacking............ Software Engineering... Agile Software Craftsmanship Who this book is for What this book is about 345566777 Part1: Debugging… Part2: Automated Testing…… Part 3: maintenance Further benefits 日B日日日 The mazerun game How to Use This book? Install the Pygame Library 10 CONTENTS nstall a text editor,… 面m ,日面a面面面a,日面面a日面面面面日面面量a日面面面B日面面 Download the Source Code Examples 0 Part l: Debugging aamammaamaa EIaa 11 Chapter2: Exceptions in Python,…,……,,,…,,,,,,,,…,13 Exceptions Are defects We know about 13 Reading the code 15 Syntax errol 15 Best Practices for Debugging SyntaxErrors 16 amining the Error Message 17 The Error type 18 The Error Description..,…,……,………………19 The traceback 20 Deductio 20 Catching Excepti 20 Best practices for Debugging I0Errors 22 Errors and defects 22 Where do defects come from? 23 The correct code 24 Best practices 25 Chapter 3: Semantic Errors in Python mmmmmmmmmmmmmmm 27 Comparing Expected and Factual Output 28 Defects…… 30 Defects in Variable Assignments. Multiple Initialization 31 Accidental Assignment………………31 Accidental Comparison ...................................................................................32 ong val s in an Expression 32 Swapped Literals in Expression CONtENTS Defects in Indexing…… 33 Creating Wrong Indices.................. Using Wrong Indices Defects in Control flow statements Defects in Boolean Expressions. Defects with indentation, mmmm 37 Defects in Using Functions. Omitting a Function call Missing Return Statement Not storing the return value Error propagation 39 Best practices Chapter 4: Debugging with the Scientific Method ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 43 Applying the Scientific Method Reproducing the Error 45 Automating the Error… 46 Isolating the defect DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD ,47 The Strip-Down Strategy........................ The Binary Search Strategy…,.,,,,,,,,,…,…,…,…,……………,48 Getting Help Taking a Break…,,,, Explain the Problem to Someone Else................50 Pair Programming Code reviews……… 50 Reading Cleaning Up 52 The scientific method and other best practices 53 Best practices 54 CONTENTS Chapter5: Debugging with print Statements,,…,…,,,,,,,…55 Diagnose Whether Code Was Executed 57 Print the content of variables 57 Pretty- Printing Data Structures......,..,………158 Simplify Input data 59 Start with Minimal Input.... 面m 日面a面面面a,日面面a日面面面面日面面a日面面面日面面量a面面画 Gradually Add More Input Data. Switching print Output On and off 63 Complete code 64 Pros and Cons of Using print Statements 65 Best practices…66 Chapter 6: Debugging with Introspection Functions mmmmmmmaammammmmmam 67 Explorative Coding in IPython.….,,,,,…,… ,68 Exploring Files and Directories....,..,,,………69 Overview of IPython Commands 70 Exploring Namespaces 70 Exploring Namespaces with dir0….,,,,,,……71 Exploring Namespaces of objects…… 72 Exploring attributes in a Python Program 73 Alternatives to dir in IPython 74 Namespace Mechanics 74 Python Uses Namespaces for Its Own Functions..........74 Modifying a Namespace 75 Namespaces and Local Scope.............. 75 Namespaces Are a Core Feature of Python Using self-Documenting objects Accessing docstrings with help0…… 778 0 bject Summaries in IPython….…78

...展开详情
试读 127P Pro-Python-Best-Practices-Debugging-Testing-and-Maintenance.pdf.pdf
立即下载
限时抽奖 低至0.43元/次
身份认证后 购VIP低至7折
一个资源只可评论一次,评论内容不能少于5个字
您会向同学/朋友/同事推荐我们的CSDN下载吗?
谢谢参与!您的真实评价是我们改进的动力~
  • 至尊王者

关注 私信
上传资源赚钱or赚积分
最新推荐
Pro-Python-Best-Practices-Debugging-Testing-and-Maintenance.pdf.pdf 9积分/C币 立即下载
1/127
Pro-Python-Best-Practices-Debugging-Testing-and-Maintenance.pdf.pdf第1页
Pro-Python-Best-Practices-Debugging-Testing-and-Maintenance.pdf.pdf第2页
Pro-Python-Best-Practices-Debugging-Testing-and-Maintenance.pdf.pdf第3页
Pro-Python-Best-Practices-Debugging-Testing-and-Maintenance.pdf.pdf第4页
Pro-Python-Best-Practices-Debugging-Testing-and-Maintenance.pdf.pdf第5页
Pro-Python-Best-Practices-Debugging-Testing-and-Maintenance.pdf.pdf第6页
Pro-Python-Best-Practices-Debugging-Testing-and-Maintenance.pdf.pdf第7页
Pro-Python-Best-Practices-Debugging-Testing-and-Maintenance.pdf.pdf第8页
Pro-Python-Best-Practices-Debugging-Testing-and-Maintenance.pdf.pdf第9页
Pro-Python-Best-Practices-Debugging-Testing-and-Maintenance.pdf.pdf第10页
Pro-Python-Best-Practices-Debugging-Testing-and-Maintenance.pdf.pdf第11页
Pro-Python-Best-Practices-Debugging-Testing-and-Maintenance.pdf.pdf第12页
Pro-Python-Best-Practices-Debugging-Testing-and-Maintenance.pdf.pdf第13页
Pro-Python-Best-Practices-Debugging-Testing-and-Maintenance.pdf.pdf第14页
Pro-Python-Best-Practices-Debugging-Testing-and-Maintenance.pdf.pdf第15页
Pro-Python-Best-Practices-Debugging-Testing-and-Maintenance.pdf.pdf第16页
Pro-Python-Best-Practices-Debugging-Testing-and-Maintenance.pdf.pdf第17页
Pro-Python-Best-Practices-Debugging-Testing-and-Maintenance.pdf.pdf第18页
Pro-Python-Best-Practices-Debugging-Testing-and-Maintenance.pdf.pdf第19页
Pro-Python-Best-Practices-Debugging-Testing-and-Maintenance.pdf.pdf第20页

试读结束, 可继续阅读

9积分/C币 立即下载