logo资料库

The Hacker's Guide to Python(Python 高手之路).pdf

第1页 / 共271页
第2页 / 共271页
第3页 / 共271页
第4页 / 共271页
第5页 / 共271页
第6页 / 共271页
第7页 / 共271页
第8页 / 共271页
资料共271页,剩余部分请下载后查看
Starting your project
Python versions
Project layout
Version numbering
Coding style & automated checks
Modules and libraries
The import system
Standard libraries
External libraries
Frameworks
Interview with Doug Hellmann
Managing API changes
Interview with Christophe de Vienne
Documentation
Getting started with Sphinx and reST
Sphinx modules
Extending Sphinx
Distribution
A bit of history
Packaging with pbr
The Wheel format
Package installation
Sharing your work with the world
Interview with Nick Coghlan
Entry points
Visualising entry 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
Testing policy
Interview with Robert Collins
Methods and decorators
Creating decorators
How methods work in Python
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
Hy
Interview with Paul Tagliamonte
Performances and optimizations
Data structures
Profiling
Ordered list and bisect
Namedtuple and slots
Memoization
PyPy
Achieving zero copy with the buffer protocol
Interview with Victor Stinner
Scaling and architecture
A note on multi-threading
Multiprocessing vs multithreading
Asynchronous and event-driven architecture
Service-oriented architecture
RDBMS and ORM
Streaming data with Flask and PostgreSQL
Interview with Dimitri Fontaine
Python 3 support strategies
Language and standard library
External libraries
Using six
Write less, code more
Single dispatcher
Context managers
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 ii . Sphinx modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Extending Sphinx . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 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 iii . Testing polic⁴ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Interview with Robert Collins . . . . . . . . . . . . . . . . . . . . . . . . . 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 iv . Namedtuple and slots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Memoi⁵ation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . P⁴P⁴ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Achieving ⁵ero cop⁴ with the buffer protocol . . . . . . . . . . . . . . . . Interview with Victor Stinner . . . . . . . . . . . . . . . . . . . . . . . . . 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 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
List of Figures . Standard package director⁴ . . . . . . . . . . . . . . . . . . . . . . . . . . . Coverage of ceilometer.publisher . . . . . . . . . . . . . . . . . . . . . . KCacheGrind example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using slice on memoryview objects . . . . . . . . . . . . . . . . . . . . . . P⁴thon base classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . P⁴thon base classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
List of Examples . A pep run . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Running pep with --ignore . . . . . . . . . . . . . . . . . . . . . . . . . . . Hy module importer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A documented API change . . . . . . . . . . . . . . . . . . . . . . . . . . . . A documented API change with warning . . . . . . . . . . . . . . . . . . . Running python -W error . . . . . . . . . . . . . . . . . . . . . . . . . . . . Code from sphinxcontrib.pecanwsme.rest.setup . . . . . . . . . . . . setup.py using distutils . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . setup.py using setuptools . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using setup.py sdist . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Result of epi group list . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Result of epi group show console_scripts . . . . . . . . . . . . . . . . . . . Result of epi ep show console_scripts coverage . . . . . . . . . . . . . . . A console script generated b⁴ setuptools . . . . . . . . . . . . . . . . . . . Running p⁴timed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Automatic virtual environment creation . . . . . . . . . . . . . . . . . . . Boostraping a venv environment . . . . . . . . . . . . . . . . . . . . . . . . A reall⁴ simple test in test_true.py . . . . . . . . . . . . . . . . . . . . . . Failing a test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Skipping tests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
LIST OF EXAMPLES vii . Using setUp with unittest . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using fixtures.EnvironmentVariable . . . . . . . . . . . . . . . . . . . . Basic mock usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Checking method calls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using mock.patch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using mock.patch to test a set of behaviour . . . . . . . . . . . . . . . . . testscenarios basic usage . . . . . . . . . . . . . . . . . . . . . . . . . . . Using testscenarios to test drivers . . . . . . . . . . . . . . . . . . . . . . Using subunit2pyunit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A .testr.conf file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Running testr run --parallel . . . . . . . . . . . . . . . . . . . . . . . . Using nosetests --with-coverage . . . . . . . . . . . . . . . . . . . . . . Using coverage with testrepository . . . . . . . . . . . . . . . . . . . . . . . A .travis.yml example file . . . . . . . . . . . . . . . . . . . . . . . . . . . A registering decorator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Source code of functools.update_wrapper in P⁴thon . . . . . . . . . Using functools.wraps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Retrieving function arguments using inspect . . . . . . . . . . . . . . . . A P⁴thon method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A P⁴thon method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Calling unbound get_si⁵e in P⁴thon . . . . . . . . . . . . . . . . . . . . . Calling unbound get_si⁵e in P⁴thon . . . . . . . . . . . . . . . . . . . . . Calling bound get_size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . @staticmethod usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Implementing an abstract method . . . . . . . . . . . . . . . . . . . . . . . Implementing an abstract method using abc . . . . . . . . . . . . . . . . Mixing @classmethod and @abstractmethod . . . . . . . . . . . . . . . . . Using super() with abstract methods . . . . . . . . . . . . . . . . . . . .
分享到:
收藏