v

您的位置:VeryCD图书计算机与网络

图书资源事务区


《Python快速入门 (英文版)》(The Quick Python Book,Second Edition)第二版[PDF]

  • 状态: 精华资源
  • 摘要:
    图书分类软件
    出版社Manning Publications Co.
    发行时间2010年01月
    语言英文
  • 时间: 2010/01/18 12:02:10 发布 | 2010/04/14 10:34:29 更新
  • 分类: 图书  计算机与网络 

see_3000

精华资源: 12

全部资源: 16

相关: 分享到新浪微博   转播到腾讯微博   分享到开心网   分享到人人   分享到QQ空间   订阅本资源RSS更新   美味书签  subtitle
该内容尚未提供权利证明,无法提供下载。
中文名Python快速入门 (英文版)
原名The Quick Python Book,Second Edition
图书分类软件
资源格式PDF
版本第二版
出版社Manning Publications Co.
书号9781935182207
发行时间2010年01月
地区美国
语言英文
简介

IPB Image

快速学习python书第二版是一本简洁清晰介绍python3的书籍,目标是新学习python 的程序员。这本更新版本囊括了所有python3版本的变化,即python从早期版本到新版本的特性变化

本书一开始用基础但是很有用的程序来传授给读者关于python的核心特性,包括语法,控制流程和数据结构。然后本书使用大型的应用程序包括代码管理,面向对象编程,web开发和转换老版本的python程序到新的版本等等。

忠实于作者的经验十足的开发者的观众,作者仔细检查普通程序特点,同时增加了更多细节关于这些python独一无二的特性仔细的介绍。


The Quick Python Book, Second Edition, is a clear, concise introduction to Python 3, aimed at programmers new to Python. This updated edition includes all the changes in Python 3, itself a significant shift from earlier versions of Python.

The book begins with basic but useful programs that teach the core features of syntax, control flow, and data structures. It then moves to larger applications involving code management, object-oriented programming, web development, and converting code from earlier versions of Python.


True to his audience of experienced developers, the author covers common programming language features concisely, while giving more detail to those features unique to Python.
IPB Image
IPB Image



目录

contents
preface xvii
acknowledgments xviii
about this book xx
PART 1 STARTING OUT ................................................. 1
1 About Python 3
1.1 Why should I use Python? 3
1.2 What Python does well 4
Python is easy to use 4 Python is expressive 4

Python is readable 5 Python is complete—“batteries

included” 6 Python is cross-platform 6 Python is free 6
■ ■
1.3 What Python doesn’t do as well 7
Python is not the fastest language 7 Python doesn’t have the

most libraries 8 Python doesn’t check variable types at

compile time 8
1.4 Why learn Python 3? 8
1.5 Summary 9
vii
viii CONTENTS
2 Getting started 10
2.1 Installing Python 10
2.2 IDLE and the basic interactive mode 12
The basic interactive mode 12 The IDLE integrated development

environment 13 Choosing between basic interactive mode and

IDLE 14
2.3 Using IDLE’s Python Shell window 14
2.4 Hello, world 15
2.5 Using the interactive prompt to explore Python 15
2.6 Summary 17
3 The Quick Python overview 18
3.1 Python synopsis 19
3.2 Built-in data types 19
Numbers 19 Lists 21 Tuples 22 Strings 23
■ ■ ■
Dictionaries 24 Sets 24 File objects 25
■ ■
3.3 Control flow structures 25
Boolean values and expressions 25 The if-elif-else

statement 26 The while loop 26 The for
■ ■
loop 27 Function definition 27 Exceptions 28
■ ■
3.4 Module creation 29
3.5 Object-oriented programming 30
3.6 Summary 31
PART 2 THE ESSENTIALS ............................................. 33
4 The absolute basics 35
4.1 Indentation and block structuring 35
4.2 Differentiating comments 37
4.3 Variables and assignments 37
4.4 Expressions 38
4.5 Strings 39
4.6 Numbers 40
Built-in numeric functions 41 Advanced numeric

functions 41 Numeric computation 41 Complex
■ ■
numbers 41 Advanced complex-number functions 42

4.7 The None value 43
ix
CONTENTS
4.8 Getting input from the user 43
4.9 Built-in operators 43
4.10 Basic Python style 43
4.11 Summary 44
5 Lists, tuples, and sets 45
5.1 Lists are like arrays 46
5.2 List indices 46
5.3 Modifying lists 48
5.4 Sorting lists 50
Custom sorting 51 The sorted() function 52

5.5 Other common list operations 52
List membership with the in operator 52 List concatenation

with the + operator 53 List initialization with the *

operator 53 List minimum or maximum with min and

max 53 List search with index 53 List matches with
■ ■
count 54 Summary of list operations 54

5.6 Nested lists and deep copies 55
5.7 Tuples 57
Tuple basics 57 One-element tuples need a

comma 58 Packing and unpacking tuples 58

Converting between lists and tuples 60
5.8 Sets 60
Set operations 60 Frozensets 61

5.9 Summary 62
6 Strings 63
6.1 Strings as sequences of characters 63
6.2 Basic string operations 64
6.3 Special characters and escape sequences 64
Basic escape sequences 65 Numeric (octal and hexadecimal) and

Unicode escape sequences 65 Printing vs. evaluating strings

with special characters 66
6.4 String methods 67
The split and join string methods 67 Converting strings to

numbers 68 Getting rid of extra whitespace 69 String
■ ■
searching 70 Modifying strings 71 Modifying strings with
■ ■
list manipulations 73 Useful methods and constants 73

x CONTENTS
6.5 Converting from objects to strings 74
6.6 Using the format method 76
The format method and positional parameters 76 The format

method and named parameters 76 Format specifiers 77

6.7 Formatting strings with % 77
Using formatting sequences 78 Named parameters and

formatting sequences 78
6.8 Bytes 80
6.9 Summary 80
7 Dictionaries 81
7.1 What is a dictionary? 82
Why dictionaries are called dictionaries 83
7.2 Other dictionary operations 83
7.3 Word counting 86
7.4 What can be used as a key? 86
7.5 Sparse matrices 88
7.6 Dictionaries as caches 88
7.7 Efficiency of dictionaries 89
7.8 Summary 89
8 Control flow 90
8.1 The while loop 90
The break and continue statements 91
8.2 The if-elif-else statement 91
8.3 The for loop 92
The range function 93 Using break and continue in for

loops 94 The for loop and tuple unpacking 94 The
■ ■
enumerate function 94 The zip function 95

8.4 List and dictionary comprehensions 95
8.5 Statements, blocks, and indentation 96
8.6 Boolean values and expressions 99
Most Python objects can be used as Booleans 99 Comparison and

Boolean operators 100
8.7 Writing a simple program to analyze a text file 101
8.8 Summary 102
xi
CONTENTS
9 Functions 103
9.1 Basic function definitions 103
9.2 Function parameter options 105
Positional parameters 105 Passing arguments by parameter

name 106 Variable numbers of arguments 107 Mixing
■ ■
argument-passing techniques 108
9.3 Mutable objects as arguments 108
9.4 Local, nonlocal, and global variables 109
9.5 Assigning functions to variables 111
9.6 lambda expressions 111
9.7 Generator functions 112
9.8 Decorators 113
9.9 Summary 114
10 Modules and scoping rules 115
10.1 What is a module? 115
10.2 A first module 116
10.3 The import statement 119
10.4 The module search path 119
Where to place your own modules 120
10.5 Private names in modules 121
10.6 Library and third-party modules 122
10.7 Python scoping rules and namespaces 123
10.8 Summary 128
11 Python programs 129
11.1 Creating a very basic program 130
Starting a script from a command line 130 Command-line

arguments 131 Redirecting the input and output of a

script 131 The optparse module 132 Using the fileinput
■ ■
module 133
11.2 Making a script directly executable on UNIX 135
11.3 Scripts on Mac OS X 135
11.4 Script execution options in Windows 135
Starting a script as a document or shortcut 136 Starting a script

from the Windows Run box 137 Starting a script from a

command window 137 Other Windows options 138

xii CONTENTS
11.5 Scripts on Windows vs. scripts on UNIX 138
11.6 Programs and modules 140
11.7 Distributing Python applications 145
distutils 145 py2exe and py2app 145 Creating executable
■ ■
programs with freeze 145
11.8 Summary 146
12 Using the filesystem 147
12.1 Paths and pathnames 148
Absolute and relative paths 148 The current working

directory 149 Manipulating pathnames 150 Useful
■ ■
constants and functions 153
12.2 Getting information about files 154
12.3 More filesystem operations 155
12.4 Processing all files in a directory subtree 156
12.5 Summary 157
13 Reading and writing files 159
13.1 Opening files and file objects 159
13.2 Closing files 160
13.3 Opening files in write or other modes 160
13.4 Functions to read and write text or binary data 161
Using binary mode 163
13.5 Screen input/output and redirection 163
13.6 Reading structured binary data with the struct module 165
13.7 Pickling objects into files 167
13.8 Shelving objects 170
13.9 Summary 171
14 Exceptions 172
14.1 Introduction to exceptions 173
General philosophy of errors and exception handling 173 A more

formal definition of exceptions 175 User-defined exceptions 176

14.2 Exceptions in Python 176
Types of Python exceptions 177 Raising exceptions 178

Catching and handling exceptions 179 Defining new

exceptions 180 Debugging programs with the assert

statement 181 The exception inheritance hierarchy 182

xiii
CONTENTS
Example: a disk-writing program in Python 182 Example:

exceptions in normal evaluation 183 Where to use

exceptions 184
14.3 Using with 184
14.4 Summary 185
15 Classes and object-oriented programming 186
15.1 Defining classes 187
Using a class instance as a structure or record 187
15.2 Instance variables 188
15.3 Methods 188
15.4 Class variables 190
An oddity with class variables 191
15.5 Static methods and class methods 192
Static methods 192 Class methods 193

15.6 Inheritance 194
15.7 Inheritance with class and instance variables 196
15.8 Private variables and private methods 197
15.9 Using @property for more flexible instance variables 198
15.10 Scoping rules and namespaces for class instances 199
15.11 Destructors and memory management 203
15.12 Multiple inheritance 207
15.13 Summary 208
16 Graphical user interfaces 209
16.1 Installing Tkinter 210
16.2 Starting Tk and using Tkinter 211
16.3 Principles of Tkinter 212
Widgets 212 Named attributes 212 Geometry management
■ ■
and widget placement 213
16.4 A simple Tkinter application 214
16.5 Creating widgets 215
16.6 Widget placement 216
16.7 Using classes to manage Tkinter applications 218
16.8 What else can Tkinter do? 219
Event handling 220 Canvas and text widgets 221

xiv CONTENTS
16.9 Alternatives to Tkinter 221
16.10 Summary 222
PART 3 ADVANCED LANGUAGE FEATURES ................... 223
17 Regular expressions 225
17.1 What is a regular expression? 225
17.2 Regular expressions with special characters 226
17.3 Regular expressions and raw strings 227
Raw strings to the rescue 228
17.4 Extracting matched text from strings 229
17.5 Substituting text with regular expressions 232
17.6 Summary 233
18 Packages 234
18.1 What is a package? 234
18.2 A first example 235
18.3 A concrete example 236
Basic use of the mathproj package 237 Loading subpackages

and submodules 238 import statements within

packages 239 __init__.py files in packages 239

18.4 The __all__ attribute 240
18.5 Proper use of packages 241
18.6 Summary 241
19 Data types as objects 242
19.1 Types are objects, too 242
19.2 Using types 243
19.3 Types and user-defined classes 243
19.4 Duck typing 245
19.5 Summary 246
20 Advanced object-oriented features 247
20.1 What is a special method attribute? 248
20.2 Making an object behave like a list 249
The __getitem__ special method attribute 249 How it

works 250 Implementing full list functionality 251

xv
CONTENTS
20.3 Giving an object full list capability 252
20.4 Subclassing from built-in types 254
Subclassing list 254 Subclassing UserList 255

20.5 When to use special method attributes 256
20.6 Metaclasses 256
20.7 Abstract base classes 258
Using abstract base classes for type checking 259 Creating

abstract base classes 260 Using the @abstractmethod and

@abstractproperty decorators 260
20.8 Summary 262
PART 4 WHERE CAN YOU GO FROM HERE? ................. 263
21 Testing your code made easy(-er) 265
21.1 Why you need to have tests 265
21.2 The assert statement 266
Python’s __debug__ variable 266
21.3 Tests in docstrings: doctests 267
Avoiding doctest traps 269 Tweaking doctests with

directives 269 Pros and cons of doctests 270

21.4 Using unit tests to test everything, every time 270
Setting up and running a single test case 270 Running the

test 272 Running multiple tests 272 Unit tests vs.
■ ■
doctests 273
21.5 Summary 273
22 Moving from Python 2 to Python 3 274
22.1 Porting from 2 to 3 274
Steps in porting from Python 2.x to 3.x 275
22.2 Testing with Python 2.6 and -3 276
22.3 Using 2to3 to convert the code 277
22.4 Testing and common problems 279
22.5 Using the same code for 2 and 3 280
Using Python 2.5 or earlier 280 Writing for Python 3.x and

converting back 281
22.6 Summary 281
xvi CONTENTS
23 Using Python libraries 282
23.1 “Batteries included”—the standard library 282
Managing various data types 283 Manipulating files and

storage 284 Accessing operating system services 285 Using
■ ■
internet protocols and formats 286 Development and debugging

tools and runtime services 286
23.2 Moving beyond the standard library 287
23.3 Adding more Python libraries 287
23.4 Installing Python libraries using setup.py 288
Installing under the home scheme 288 Other installation

options 289
23.5 PyPI, a.k.a. “the Cheese Shop” 289
23.6 Summary 289
24 Network, web, and database programming 290
24.1 Accessing databases in Python 291
Using the sqlite3 database 291
24.2 Network programming in Python 293
Creating an instant HTTP server 293 Writing an HTTP

client 294
24.3 Creating a Python web application 295
Using the web server gateway interface 295 Using the wsgi

library to create a basic web app 295 Using frameworks to create

advanced web apps 296
24.4 Sample project—creating a message wall 297
Creating the database 297 Creating an application

object 298 Adding a form and retrieving its contents

298 Saving the form’s contents 299 Parsing the URL and
■ ■
retrieving messages 300 Adding an HTML wrapper 303

24.5 Summary 304
appendix 305
index 323

正在读取……

这里是其它用户补充的资源(我也要补充):

暂无补充资源
正在加载,请稍等...

点击查看所有48网友评论

 

(?) [公告]留口水、评论相关规则 | [活动]每日签到 轻松领取电驴经验

    小贴士:
  1. 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  2. 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  3. 勿催片。请相信驴友们对分享是富有激情的,如果确有更新版本,您一定能搜索到。
  4. 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
  5. 如果您发现自己的评论不见了,请参考以上4条。