Expert Python Programming [Second edition] 9781785884399, 1785884395, 978-1-78588-685-0, 1785886851

Annotation Become an ace Python programmer by learning best coding practices and advance-level concepts with Python 3.5A

460 83 3MB

English Pages 536 Year 2016

Report DMCA / Copyright

DOWNLOAD FILE

Expert Python Programming [Second edition]
 9781785884399, 1785884395, 978-1-78588-685-0, 1785886851

Table of contents :
Content: Cover
Copyright
Credits
About the Authors
About the Reviewer
www.PacktPub.com
Table of Contents
Preface
Chapter 1: Current Status of Python
Where are we now and where we are going?
Why and how does Python change?
Getting up to date with changes --
PEP documents
Python 3 adoption at the time of writing this book
The main differences between Python 3 and Python 2
Why should I care?
The main syntax differences and common pitfalls
Syntax changes
Changes in the standard library
Changes in datatypes and collections. The popular tools and techniques used for maintaining cross-version compatibilityNot only CPython
Why should I care?
Stackless Python
Jython
IronPython
PyPy
Modern approaches to Python development
Application-level isolation of Python environments
Why isolation?
Popular solutions
virtualenv
venv
buildout
Which one to choose?
System-level environment isolation
Virtual development environments using Vagrant
Containerization versus virtualization
Popular productivity tools
Custom Python shells --
IPython, bpython, ptpython, and so on. Setting up the PYTHONSTARTUP environment variableIPython
bpython
ptpython
Interactive debuggers
Useful resources
Summary
Chapter 2: Syntax Best Practices --
below the Class Level
Python's built-in types
Strings and bytes
Implementation details
String concatenation
Collections
Lists and tuples
Dictionaries
Sets
Beyond basic collections --
the collections module
Advanced syntax
Iterators
The yield statement
Decorators
General syntax and possible implementations
Usage and useful examples
Context managers --
the with statement
General syntax and possible implementations. Other syntax elements you may not know yetThe for ... else ... statement
Function annotations
The general syntax
The possible uses
Summary
Chapter 3: Syntax Best Practices --
above the Class Level
Subclassing built-in types
Accessing methods from superclasses
Old-style classes and super in Python 2
Understanding Python's Method Resolution Order
super pitfalls
Mixing super and explicit class calls
Heterogeneous arguments
Best practices
Advanced attribute access patterns
Descriptors
Real-life example --
lazily evaluated attributes
Properties
Slots
Metaprogramming. Decorators --
a method of metaprogrammingClass decorators
Using the __new__() method to override instance creation process
Metaclasses
The general syntax
New Python 3 syntax for metaclasses
Metaclass usage
Metaclass pitfalls
Some tips on code generation
exec, eval, and compile
Abstract Syntax Tree
Projects using code generation patterns
Summary
Chapter 4: Choosing Good Names
PEP 8 and naming best practices
Why and when to follow PEP 8?
Beyond PEP 8 --
team-specific style guidelines
Naming styles
Variables
Constants
Naming and usage
Public and private variables.

Polecaj historie