Mastering Python 9781785289729, 1785289721, 9781785289132, 1785289136

Master the art of writing beautiful and powerful Python by using all of the features that Python 3.5 offersAbout This Bo

917 91 3MB

English Pages 486 Year 2016

Report DMCA / Copyright

DOWNLOAD EPUB FILE

Table of contents :
Cover
Copyright
Credits
About the Author
About the Reviewers
www.PacktPub.com
Table of Contents
Preface
Chapter 1: Getting Started --
One Environment per Project
Creating a virtual Python environment using venv
Creating your first venv
venv arguments
Differences between virtualenv and venv
Bootstrapping pip using ensurepip
ensurepip usage
Manual pip install
Installing C/C++ packages
Debian and Ubuntu
Red Hat, CentOS, and Fedora
OS X
Windows
Summary
Chapter 2: Pythonic Syntax, Common Pitfalls, and Style Guide
Code style --
or what is Pythonic code? Formatting strings --
printf-style or str.format?PEP20, the Zen of Python
Beautiful is better than ugly
Explicit is better than implicit
Simple is better than complex
Flat is better than nested
Sparse is better than dense
Readability counts
Practicality beats purity
Errors should never pass silently
In the face of ambiguity, refuse the temptation to guess
One obvious way to do it
Now is better than never
Hard to explain, easy to explain
Namespaces are one honking great idea
Conclusion
Explaining PEP8
Duck typing
Differences between value and identity comparisons
Loops. Maximum line lengthVerifying code quality, pep8, pyflakes, and more
flake8
Pylint
Common pitfalls
Scope matters!
Function arguments
Class properties
Modifying variables in the global scope
Overwriting and/or creating extra built-ins
Modifying while iterating
Catching exceptions --
differences between Python 2 and 3
Late binding --
be careful with closures
Circular imports
Import collisions
Summary
Chapter 3: Containers and Collections --
Storing Data the Right Way
Time complexity --
the big O notation
Core collections
list --
a mutable list of items. Dict --
unsorted but a fast map of itemsset --
like a dict without values
tuple --
the immutable list
Advanced collections
ChainMap --
the list of dictionaries
counter --
keeping track of the most occurring elements
deque --
the double ended queue
defaultdict --
dictionary with a default value
namedtuple --
tuples with field names
enum --
a group of constants
OrderedDict --
a dictionary where the insertion order matters
heapq --
the ordered list
bisect --
the sorted list
Summary
Chapter 4: Functional Programming --
Readability versus Brevity
Functional programming
list comprehensions. Dict comprehensionsset comprehensions
lambda functions
The Y combinator
functools
partial --
no need to repeat all arguments every time
reduce --
combining pairs into a single result
Implementing a factorial function
Processing trees
itertools
accumulate --
reduce with intermediate results
chain --
combining multiple results
combinations --
combinatorics in Python
permutations --
combinations where the order matters
compress --
selecting items using a list of Booleans
dropwhile/takewhile --
selecting items using a function
count --
infinite range with decimal steps. Groupby --
grouping your sorted iterable.

Mastering Python
 9781785289729, 1785289721, 9781785289132, 1785289136

  • 0 0 0
  • Like this paper and download? You can publish your own PDF file online for free in a few minutes! Sign Up
Recommend Papers