The Hacker's Guide To Python.pdf

(2034 KB) Pobierz
Contents
Starting your project
.
.
.
.
P⁴thon versions
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Project la⁴out
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Version numbering
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Coding st⁴le & automated checks
. . . . . . . . . . . . . . . . . . . . . .
Modules and libraries
.
.
.
.
.
.
.
The import s⁴stem
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Standard libraries
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
External libraries
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Frameworks
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Interview with Doug Hellmann
. . . . . . . . . . . . . . . . . . . . . . . .
Managing API changes
. . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Interview with Christophe de Vienne
. . . . . . . . . . . . . . . . . . . .
Documentation
.
Getting started with Sphinx and reST
. . . . . . . . . . . . . . . . . . . .
CONTENTS
.
.
Sphinx modules
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Extending Sphinx
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ii
Distribution
.
.
.
.
.
.
.
A bit of histor⁴
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Packaging with
pbr
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
The
Wheel
format
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Package installation
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Sharing ⁴our work with the world
. . . . . . . . . . . . . . . . . . . . . .
Interview with Nick Coghlan
. . . . . . . . . . . . . . . . . . . . . . . . . .
Entr⁴ points
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. .
. .
. .
Visualising entr⁴ points
. . . . . . . . . . . . . . . . . . . . . . . .
Using console scripts
. . . . . . . . . . . . . . . . . . . . . . . . .
Using plugins and drivers
. . . . . . . . . . . . . . . . . . . . . . .
Virtual environments
Unit testing
.
.
.
.
.
.
.
The basics
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Fixtures
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Mocking
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Scenarios
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Test streaming and parallelism
. . . . . . . . . . . . . . . . . . . . . . . .
Coverage
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Using virtualenv with tox
. . . . . . . . . . . . . . . . . . . . . . . . . . . .
CONTENTS
.
.
Testing polic⁴
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Interview with Robert Collins
. . . . . . . . . . . . . . . . . . . . . . . . .
iii
Methods and decorators
.
.
.
.
.
.
.
Creating decorators
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
How methods work in P⁴thon
. . . . . . . . . . . . . . . . . . . . . . . . .
Static methods
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Class method
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Abstract methods
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Mixing static, class, and abstract methods
. . . . . . . . . . . . . . . . .
The truth about
super
. . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Functional programming
.
.
.
Generators
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
List comprehensions
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Functional functions functioning
. . . . . . . . . . . . . . . . . . . . . . .
The AST
.
.
H⁴
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Interview with Paul Tagliamonte
. . . . . . . . . . . . . . . . . . . . . . .
Performances and optimizations
.
.
.
Data structures
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Profiling
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Ordered list and bisect
. . . . . . . . . . . . . . . . . . . . . . . . . . . . .
CONTENTS
.
.
.
.
.
Namedtuple and slots
. . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Memoi⁵ation
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
P⁴P⁴
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Achieving ⁵ero cop⁴ with the buffer protocol
. . . . . . . . . . . . . . .
Interview with Victor Stinner
. . . . . . . . . . . . . . . . . . . . . . . . .
iv
Scaling and architecture
.
.
.
.
A note on multi-threading
. . . . . . . . . . . . . . . . . . . . . . . . . . .
Multiprocessing vs multithreading
. . . . . . . . . . . . . . . . . . . . . .
As⁴nchronous and event-driven architecture
. . . . . . . . . . . . . . .
Service-oriented architecture
. . . . . . . . . . . . . . . . . . . . . . . . .
RDBMS and ORM
.
.
Streaming data with Flask and PostgreSQL
. . . . . . . . . . . . . . . .
Interview with Dimitri Fontaine
. . . . . . . . . . . . . . . . . . . . . . . .
Python support strategies
.
.
.
Language and standard librar⁴
. . . . . . . . . . . . . . . . . . . . . . . .
External libraries
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Using six
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Write less, code more
.
.
Single dispatcher
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Context managers
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Zgłoś jeśli naruszono regulamin