Table of Contents
Preface
Chapter 1: Getting started
Chapter 2: Syntax Best Practices—Below the Class Level
Chapter 3: Syntax Best Practices—Above the Class Level
Chapter 4: Choosing Good Names
Chapter 5: Writing a Package
Chapter 6: Writing an Application
Chapter 7: Working with zc.buildout
Chapter 8: Managing Code
Chapter 9: Managing Life Cycle
Chapter 10: Documenting Your Project
Chapter 11: Test-Driven Development
Chapter 12: Optimization: General Principles and Profiling Techniques
Chapter 13: Optimization: Solutions
Chapter 14: Useful Design Patterns
Index
- Chapter 1: Getting started
- Installing Python
- Python Implementations
- Jython
- IronPython
- PyPy
- Other Implementations
- Linux Installation
- Package Installation
- Compiling the Sources
- Windows Installation
- Installing Python
- Installing MinGW
- Installing MSYS
- Mac OS X Installation
- Package Installation
- Compiling the Source
- Python Implementations
- The Python Prompt
- Customizing the Interactive Prompt
- iPython: An Advanced Prompt
- Customizing the Interactive Prompt
- Installing setuptools
- Understanding How It Works
- setuptools Installation Using EasyInstall
- Hooking MinGW into distutils
- Working Environment
- Using an Editor and Complementary Tools
- Code Editor
- Installing and Configuring Vim
- Using Another Editor
- Extra Binaries
- Using an Integrated Development Environment
- Installing Eclipse with PyDev
- Using an Editor and Complementary Tools
- Summary
- Installing Python
- Chapter 2: Syntax Best Practices—Below the Class Level
- List Comprehensions
- Iterators and Generators
- Generators
- Coroutines
- Generator Expressions
- The itertools Module
- islice: The Window Iterator
- tee: The Back and Forth Iterator
- groupby: The uniq Iterator
- Other Functions
- Decorators
- How to Write a Decorator
- Argument checking
- Caching
- Proxy
- Context Provider
- with and contextlib
- The contextlib Module
- Context Example
- Summary
- Chapter 3: Syntax Best Practices—Above the Class Level
- Subclassing Built-in Types
- Accessing Methods from Superclasses
- Understanding Python's Method Resolution Order (MRO)
- super Pitfalls
- Mixing super and classic Calls
- Heterogeneous Arguments
- Best Practices
- Descriptors and Properties
- Descriptors
- Introspection Descriptor
- Meta-descriptor
- Properties
- Descriptors
- Slots
- Meta-programming
- The__new__ Method
- __metaclass__ Method
- Summary
- Chapter 4: Choosing Good Names
- PEP 8 and Naming Best Practices
- Naming Styles
- Variables
- Constants
- Public and Private Variables
- Functions and Methods
- The Private Controversy
- Special Methods
- Arguments
- Properties
- Classes
- Modules and Packages
- Variables
- Naming Guide
- Use "has" or "is" Prefix for Boolean Elements
- Use Plural for Elements That Are Sequences
- Use Explicit Names for Dictionaries
- Avoid Generic Names
- Avoid Existing Names
- Best Practices for Arguments
- Build Arguments by Iterative Design
- Trust the Arguments and Your Tests
- Use *args and **kw Magic Arguments Carefully
- Class Names
- Module and Package Names
- Working on APIs
- Tracking Verbosity
- Building the Namespace Tree
- Splitting the Code
- Using Eggs
- Using a Deprecation Process
- Useful Tools
- Pylint
- CloneDigger
- Summary
- Chapter 5: Writing a Package
- A Common Pattern for All Packages
- setup.py, the Script That Controls Everything
- sdist
- build and bdist
- bdist_egg
- install
- How to Uninstall a Package
- develop
- test
- register and upload
- Creating a New Command
- setup.py Usage Summary
- Other Important Metadata
- setup.py, the Script That Controls Everything
- The Template-Based Approach
- Python Paste
- Creating Templates
- Creating the Package Template
- Development Cycle
- Summary
- A Common Pattern for All Packages
- Chapter 6: Writing an Application
- Atomisator: An Introduction
- Overall Picture
- Working Environment
- Adding a Test Runner
- Adding a packages Structure
- Writing the Packages
- atomisator.parser
- Creating the Initial Package
- Creating the Initial doctest
- Building the Test Environment
- Writing the Code
- atomisator.db
- SQLAlchemy
- Providing the APIs
- atomisator.feed
- atomisator.main
- atomisator.parser
- Distributing Atomisator
- Dependencies between Packages
- Summary
- Chapter 7: Working with zc.buildout
- zc.buildout Philosophy
- Configuration File Structure
- Minimum Configuration File
- [buildout] Section Options
- The buildout Command
- Recipes
- Notable Recipes
- Creating Recipes
- Atomisator buildout Environment
- buildout Folder Structure
- Going Further
- Configuration File Structure
- Releasing and Distributing
- Releasing the Packages
- Adding a Release Configuration File
- Building and Releasing the Application
- Summary
- zc.buildout Philosophy
- Chapter 8: Managing Code
- Version Control Systems
- Centralized Systems
- Distributed Systems
- Distributed Strategies
- Centralized or Distributed?
- Mercurial
- Project Management with Mercurial
- Setting Up a Dedicated Folder
- Configuring hgwebdir
- Configuring Apache
- Setting Up Authorizations
- Setting Up the Client Side
- Continuous Integration
- Buildbot
- Installing Buildbot
- Hooking Buildbot and Mercurial
- Hooking Apache and Buildbot
- Buildbot
- Summary
- Version Control Systems
- Chapter 9: Managing Life Cycle
- Different Approaches
- Waterfall Development Model
- Spiral Development Model
- Iterative Development Model
- Defining a Life Cycle
- Planning
- Development
- Global Debug
- Release
- Setting Up a Tracking System
- Trac
- Installation
- Apache Settings
- Permission Settings
- Project Life Cycle with Trac
- Planning
- Development
- Cleaning
- Release
- Trac
- Summary
- Different Approaches
- Chapter 10: Documenting Your Project
- The Seven Rules of Technical Writing
- Write in Two Steps
- Target the Readership
- Use a Simple Style
- Limit the Scope of the Information
- Use Realistic Code Examples
- Use a Light but Sufficient Approach
- Use Templates
- A reStructuredText Primer
- Section Structure
- Lists
- Inline Markup
- Literal Block
- Links
- Building the Documentation
- Building the Portfolio
- Design
- Usage
- Operations
- Building the Portfolio
- Make Your Own Portfolio
- Building the Landscape
- Producer's Layout
- Consumer's Layout
- Building the Landscape
- Summary
- The Seven Rules of Technical Writing
- Chapter 11: Test-Driven Development
- I Don't Test
- Test-Driven Development Principles
- Preventing Software Regression
- Improving Code Quality
- Providing the Best Developer Documentation
- Producing Robust Code Faster
- What Kind of Tests?
- Acceptance Tests
- Unit Tests
- Python Standard Test Tools
- Test-Driven Development Principles
- I Do Test
- Unittest Pitfalls
- Unittest Alternatives
- nose
- py.test
- Fakes and Mocks
- Building a Fake
- Using Mocks
- Document-Driven Development
- Writing a Story
- Summary
- I Don't Test
- Chapter 12: Optimization: General Principles and Profiling Techniques
- The Three Rules of Optimization
- Make It Work First
- Work from the User's Point of View
- Keep the Code Readable(and thus maintainable)
- Optimization Strategy
- Find Another Culprit
- Scale the Hardware
- Write a Speed Test
- Finding Bottlenecks
- Profiling CPU Usage
- Macro-Profiling
- Micro-Profiling
- Measuring Pystones
- Profiling Memory Usage
- How Python Deals with Memory
- Profiling Memory
- Profiling Network Usage
- Profiling CPU Usage
- Summary
- The Three Rules of Optimization
- Chapter 13: Optimization: Solutions
- Reducing the Complexity
- Measuring Cyclomatic Complexity
- Measuring the Big-O Notation
- Simplifying
- Searching in a List
- Using a Set Instead of a List
- Cut the External Calls, Reduce the Workload
- Using Collections
- Multithreading
- What is Multithreading?
- How Python Deals with Threads
- When Should Threading Be Used?
- Building Responsive Interfaces
- Delegating Work
- Multi-User Applications
- Simple Example
- Multiprocessing
- Pyprocessing
- Caching
- Deterministic Caching
- Non-Deterministic Caching
- Pro-Active Caching
- Memcached
- Summary
- Reducing the Complexity
- Chapter 14: Useful Design Patterns
- Creational Patterns
- Singleton
- Structural Patterns
- Adapter
- Interfaces
- Proxy
- Facade
- Adapter
- Behavioral Patterns
- Observer
- Visitor
- Template
- Summary
- Creational Patterns