ebook img

The Hitchhiker's Guide To Python PDF

322 Pages·2016·5.93 MB·English
by  
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 The Hitchhiker's Guide To Python

The Hitchhiker’s G uide to Python BEST PRACTICES FOR DEVELOPMENT Kenneth Reitz & Tanya Schlusser www.allitebooks.com www.allitebooks.com The Hitchhiker’s Guide to Python Best Practices for Development Kenneth Reitz and Tanya Schlusser Beijing Boston Farnham Sebastopol Tokyo www.allitebooks.com The Hitchhiker’s Guide to Python by Kenneth Reitz and Tanya Schlusser Copyright © 2016 Kenneth Reitz, Tanya Schlusser. All rights reserved. Printed in the United States of America. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://safaribooksonline.com). For more information, contact our corporate/ institutional sales department: 800-998-9938 or Dedicated to you www.allitebooks.com www.allitebooks.com Table of Contents Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi Part I. Getting Started 1. Picking an Interpreter. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 The State of Python 2 Versus Python 3 3 Recommendations 4 So…3? 4 Implementations 5 CPython 5 Stackless 5 PyPy 6 Jython 6 IronPython 6 PythonNet 6 Skulpt 7 MicroPython 7 2. Properly Installing Python. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Installing Python on Mac OS X 9 Setuptools and pip 11 virtualenv 11 Installing Python on Linux 12 Setuptools and pip 12 Development Tools 13 virtualenv 14 Installing Python on Windows 15 v www.allitebooks.com Setuptools and pip 17 virtualenv 18 Commercial Python Redistributions 18 3. Your Development Environment. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 Text Editors 22 Sublime Text 23 Vim 23 Emacs 25 TextMate 26 Atom 26 Code 27 IDEs 27 PyCharm/IntelliJ IDEA 29 Aptana Studio 3/Eclipse + LiClipse + PyDev 29 WingIDE 30 Spyder 30 NINJA-IDE 30 Komodo IDE 31 Eric (the Eric Python IDE) 31 Visual Studio 32 Enhanced Interactive Tools 32 IDLE 32 IPython 33 bpython 33 Isolation Tools 33 Virtual Environments 34 pyenv 36 Autoenv 36 virtualenvwrapper 37 Buildout 38 Conda 38 Docker 39 Part II. Getting Down to Business 4. Writing Great Code. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 Code Style 43 PEP 8 44 PEP 20 (a.k.a. The Zen of Python) 45 General Advice 46 vi | Table of Contents www.allitebooks.com Conventions 52 Idioms 54 Common Gotchas 58 Structuring Your Project 61 Modules 61 Packages 65 Object-Oriented Programming 66 Decorators 67 Dynamic Typing 68 Mutable and Immutable Types 69 Vendorizing Dependencies 71 Testing Your Code 72 Testing Basics 74 Examples 76 Other Popular Tools 80 Documentation 82 Project Documentation 82 Project Publication 83 Docstring Versus Block Comments 84 Logging 84 Logging in a Library 85 Logging in an Application 86 Choosing a License 88 Upstream Licenses 88 Options 88 Licensing Resources 90 5. Reading Great Code. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91 Common Features 92 HowDoI 93 Reading a Single-File Script 93 Structure Examples from HowDoI 96 Style Examples from HowDoI 97 Diamond 99 Reading a Larger Application 100 Structure Examples from Diamond 105 Style Examples from Diamond 109 Tablib 112 Reading a Small Library 112 Structure Examples from Tablib 116 Style Examples from Tablib 124 Requests 126 Table of Contents | vii www.allitebooks.com Reading a Larger Library 126 Structure Examples from Requests 130 Style Examples from Requests 135 Werkzeug 140 Reading Code in a Toolkit 141 Style Examples from Werkzeug 148 Structure Examples from Werkzeug 149 Flask 155 Reading Code in a Framework 156 Style Examples from Flask 162 Structure Examples from Flask 163 6. Shipping Great Code. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167 Useful Vocabulary and Concepts 168 Packaging Your Code 169 Conda 169 PyPI 170 Freezing Your Code 172 PyInstaller 174 cx_Freeze 176 py2app 177 py2exe 178 bbFreeze 178 Packaging for Linux-Built Distributions 179 Executable ZIP Files 180 Part III. Scenario Guide 7. User Interaction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185 Jupyter Notebooks 185 Command-Line Applications 186 GUI Applications 194 Widget Libraries 194 Game Development 200 Web Applications 200 Web Frameworks/Microframeworks 201 Web Template Engines 204 Web Deployment 209 8. Code Management and Improvement. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213 Continuous Integration 213 viii | Table of Contents www.allitebooks.com

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.