没有合适的资源?快使用搜索试试~ 我知道了~
首页Mastering Python 原版PDF by Hattem
Mastering Python 原版PDF by Hattem
需积分: 10 99 浏览量
更新于2023-03-16
评论
收藏 3.45MB PDF 举报
Python is a language that is easy to learn and both powerful and convenient from the start. Mastering Python, however, is a completely different question. Every programming problem you will encounter has at least several possible solutions and/or paradigms to apply within the vast possibilities of Python. This book will not only illustrate a range of different and new techniques but also explain where and when a method should be applied.
资源详情
资源评论
资源推荐


Mastering Python
Master the art of writing beautiful and powerful Python
by using all of the features that Python 3.5 offers
Rick van Hattem
BIRMINGHAM - MUMBAI

Mastering Python
Copyright © 2016 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval
system, or transmitted in any form or by any means, without the prior written
permission of the publisher, except in the case of brief quotations embedded in
critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy
of the information presented. However, the information contained in this book is
sold without warranty, either express or implied. Neither the author, nor Packt
Publishing, and its dealers and distributors will be held liable for any damages
caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the
companies and products mentioned in this book by the appropriate use of capitals.
However, Packt Publishing cannot guarantee the accuracy of this information.
First published: April 2016
Production reference: 1270416
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78528-972-9
www.packtpub.com

[ i ]
Table of Contents
Preface xi
Chapter 1: Getting Started – One Environment per Project 1
Creating a virtual Python environment using venv 2
Creating your rst venv 3
venv arguments 4
Differences between virtualenv and venv 6
Bootstrapping pip using ensurepip 7
ensurepip usage 7
Manual pip install 7
Installing C/C++ packages 8
Debian and Ubuntu 9
Red Hat, CentOS, and Fedora 9
OS X 9
Windows 10
Summary 11
Chapter 2: Pythonic Syntax, Common Pitfalls, and Style Guide 13
Code style – or what is Pythonic code? 14
Formatting strings – printf-style or str.format? 15
PEP20, the Zen of Python 15
Beautiful is better than ugly 16
Explicit is better than implicit 17
Simple is better than complex 18
Flat is better than nested 20
Sparse is better than dense 20
Readability counts 21
Practicality beats purity 21
Errors should never pass silently 22
In the face of ambiguity, refuse the temptation to guess 24
One obvious way to do it 24
Now is better than never 25

Table of Contents
[ ii ]
Hard to explain, easy to explain 25
Namespaces are one honking great idea 25
Conclusion 26
Explaining PEP8 27
Duck typing 27
Differences between value and identity comparisons 29
Loops 30
Maximum line length 31
Verifying code quality, pep8, pyakes, and more 32
ake8 32
Pylint 35
Common pitfalls 35
Scope matters! 36
Function arguments 36
Class properties 37
Modifying variables in the global scope 38
Overwriting and/or creating extra built-ins 39
Modifying while iterating 41
Catching exceptions – differences between Python 2 and 3 42
Late binding – be careful with closures 44
Circular imports 45
Import collisions 47
Summary 48
Chapter 3: Containers and Collections – Storing Data the
Right Way 49
Time complexity – the big O notation 50
Core collections 51
list – a mutable list of items 52
dict – unsorted but a fast map of items 55
set – like a dict without values 57
tuple – the immutable list 59
Advanced collections 62
ChainMap – the list of dictionaries 62
counter – keeping track of the most occurring elements 64
deque – the double ended queue 66
defaultdict – dictionary with a default value 68
namedtuple – tuples with eld names 71
enum – a group of constants 72
OrderedDict – a dictionary where the insertion order matters 74
heapq – the ordered list 75
bisect – the sorted list 76
Summary 79
剩余480页未读,继续阅读














安全验证
文档复制为VIP权益,开通VIP直接复制

评论0