文件名称:
A-Python-Book-Beginning-Python-Advanced-Python-and-Python-Exercises.pdf
开发工具:
文件大小: 1mb
下载次数: 0
上传时间: 2019-09-13
详细说明:A-Python-Book-Beginning-Python-Advanced-Python-and-Python-ExercisesA Python book
Contents
1 Part 1-Beginning Python
1.1 Introductions etc
10
1.1.1 Resources..................1
1.1.2 A general description of Python………,12
1.1.3 Interactive python
15
1.2 Lexical matters..wAONOOOO..15
1.2.1 Lines
着·垂
。着D垂
15
1.2.2 Comments…
16
1.2.3 Names and tokens
16
1.2.4 Blocks and indentation
16
1.2.5 Doc strings…………
17
1. 2.6 Program structure
17
1.2.7 Operators
18
1.2.8 Also see
19
1.2.9 Code evaluati0n...……19
1.3 Statements and
1.4 Built- in data-types……
1.4.1 Numeric types……
.…·:···:·················
21
1.4.2 Tuples and lists
21
1. 4.3 Strings
24
1.4.3.1 The new string
1.4.3.2 Unicode strings.……….……….……….……….……….27
1.44 Dictionaries
29
1. 45 Files
32
1. 4.6 Other built-in types..........35
1. 4.6. 1 The None value/type
1. 4.6.2 Boolean values. ......................................................................................36
1. 4.6.3 Sets and frozensets
…36
1.5 Functions and classes --A Preview
36
1.6 Statements
37
1.6.1 Assignment statement…….……37
1.6.2 import statement
39
1.6.3 print statement...........41
1. 6. 4 if; clif: clsc statement
43
1. 6.5 for: statement
14
1. 6. 6 while: statement
…48
age
A Python book
1.6.7 continue and break statements……98
1.6.8 try except: statement
·.·
49
1. 6.9 raise statement
51
1. 10 with: statement
52
1.6.10.1 Writing a context manager:………….….….….….….….….….…….……....52
1. 6.10.2 Using the with statement .,....
53
1.6.11del
154
1.6.12 case statement.……………………………5
1.7 Functions, Modules, Packages, and debugging
55
1.7.Ⅰ Functions.…5
1.7.1.1 The def statement
55
1.7.1.2 Returning values
55
1.7.1. 3 Paramcters
56
I.7.1. 4 Arguments
·.···:··.·····:.·······:········.·:.·:·····:····:·.·:····:·····:·.·····
56
1.7.1.5 Local variables
57
1.7.1.6 Other things to know about functions
·····
57
1.7. 1.7 Global variables and the global statement
58
1.7.1.8 Doc strings for functions......,……………60
1.7. 1.9 Decorators for functions
.60
1.7.21 ambda..
1.7.3 Iterators and generators
62
1. 7. 4 Modules
67
1. 7.4.1 Doc strings for modules
·:·.·
68
1.7.5 Pack
中·
68
1. 8 Cla
69
18.1 A simple class…
9
1.8.2 Defining methods
70
1. 8. 3 The constructor. ................,............................................................................70
1.8.4 Member variables
70
1.8.5 Calling methods
1.8.6 Adding inheritance....,.,.,…,,…,71
1. 8. 7 Class variables
72
1. 8.8 Class methods and static methods
72
1.8.9 Properties.........74
1.8.10 Interfaces..............................75
1. 8.11 New-style classes.........
1.8.12 Doc strings for classes
…7
1. 8. 3 Private members
..77
1.9 Special Tasks...............
77
1.9. 1 Debugging tools
77
A Python book
1.9.2 File input and output....,,…,,…,…,…,…,……………………78
1.9.3 Unit tests
.80
1.9.3. 1 A Simple example
.80
1.9.3.2 Unit test suites............................................ 81
1.9.3.3 Additional unittest features...........................83
1.9.3.4 Guidance on Unit Testing……….….….….….….…....…..…..85
1.9.4 doctest
:··········
.85
1.9.5 The Python database APl
鲁着。·。音··音音音。普D非音
看·音·音。音,着自音。,音音
87
1.9.6 Installing Python packages
8
10 More Python Features and Exercises.
2 Part 2-- Advanced Python
中·中:
90
2. 1 Introduction--Python 201--(Slightly) Advanced Python Topics......90
2.2 Regular expressions..........,.….……………90
2.2.1 Defining regular expressions..........
2.2.2 Compiling regular expressions
91
2.2.3 Using regular expressions
2.2. 4 USing match objects to extract a value
·····:·;···
92
2.2.5 Extracting multiple items
2.2.6 Replacing multiple items.………,……………………94
2.3 Iterator Objects
96
2.3.1 Example- A generator function.………….……98
2.3.2 Examplc-A class containing a generator mcthod...........100
233 Example- An iterator class……………
102
2.3.4 Example- An iterator class that uses yield
.104
2.3.5 Example-A
105
2.3.6 Example-A generator expression
105
2. 4 Unit Tests
106
2.4. I Defining unit tests…….…….….….….….…..….……………………….106
2.4.1.1 Create a test class
106
2.5 Extending and embedding Python
……109
2.5.1 Introduction and concepts..….….…..…...109
2.5.2 Extension modules. ......................................................................................110
2.5.3 SWIG
112
2.5.4Prex.......115
2.5.5 SWIG VS Pyrex
…………120
2.5.6 Cython.……,…,……,…,…,…,…,…,…,…,……120
2.5.7 Extension types.…….....…..,.…....12
2.5.8 Extension classes
122
2.6 Parsing..
,垂D鲁。,鲁垂·垂垂·垂.D非着非音垂
12
2.6. 1 Special purpose parsers
…123
age
A Python book
2.6.2 Writing a recursive descent parser by hand........................ 124
2.6.3 Creating a lexer/tokenizer with Plex.......................131
2.6.4 A survey of existing tools
…141
2.6.5 Creating a parser with Ply
141
2.6.6 Creating a parser with pyparsing…………………,148
2.6.6. 1 Parsing comma-delimited lines
148
2.6.6.2 Parsing functors
·
.149
2.6.6.3 Parsing names, phone numbers, etc.................150
2.6.6.4 A more complex example
151
2.7 GUI Applications.………….….….….….….….….…………………153
2.7.1 Introduction
···:··
∴153
2.7.2 PyGtk
………153
2.7.2. 1 A simple message dialog box.....................153
2.7.2.2 A simple text input dialog box………………………………156
2.7.2.3 A file selection dialog box. .................................................................158
2.7.3 Easy GUI...........................160
2.7.3.1 A Simple Easy
2.7.3.2 An Easy GuI file open dialog example................161
2. 8 Guidance on packages and modules,,..,.,..
161
2.8.1 Introduction
161
2.8.2 Implementing Packages
162
2.8.3 USing Packages
。·音。
162
2.8.4 Distributing and Installing Packages.……………62
2.9 End matter
164
2.9.1 Acknowledgements and Thanks..……164
2.9.2 See also.…
…………164
3Part3- Python Workbook………
165
3.1 Introduction.
3.2 Lexical structures
165
3.2.1 Variables and names.
3.2.2 Line structure
3.2.3 Indentation and program structure……………………….168
3.3Eⅹ ecution model
.169
3. Built-in Data Types.
3.4.1 Numbers
,170
3.4.1.1 Literal representations of numbers
…171
34.1.2 Operators for numbers………
173
3.4.13 Methods on numbers
175
3.4.2 Lists
………………175
3.4.2.1 Literal representation of lists………176
A Python book
3.4.2.2 Operators on lists……………….………
·······················
178
3.4.2.3 Methods on lists
中··,·····,····.··.···,·····中·
178
34.24 List comprehensions.....……180
34.3 Strings..................…182
3.4.3.1 Characters. ...........................................................................................183
3.4.3.2 Operators on strings
…184
3.4.3.3 Methods on strings
185
3.4.3.4 Raw strings....... 187
3.4.3. 5 Unicode strings
·····:··········:······;····;
188
3.4.4 Dictionaries
190
3.4.4.1 Literal representation of dictionaries
.190
344.2 Operators on dictionaries...…………………,191
3.4.4.3 Methods on dictionaries.
3.4.5上iles.
195
3.4.6 A few miscellaneous data types………...….…..…197
3.4.6.1NOne.
······
197
3.4.6.2 The booleans True and False.............................. 197
3.5 Statements
………198
3.5.1 assignment statement.…………,198
3.5.2 print statement
200
3.5.3 if statement exercises
201
3. 5. 4 for: statement cxcrciscs................. 202
3.5.5 while: statement exercises. ............................................................205
3.5.6 break and continue statements
206
3.5.7 Exceptions and the try: except: and raise statements
207
3.6 Functions
…………………210
3.6.1 Optional arguments and default values….….…....2ll
3.6.2 Passing functions as arguments
213
3.6.3 Extra args and key word args
214
3.6.3.1 Order of arguments(positional, extra, and keyword args).....216
3.6. 4 Functions and duck-typing and polymorphi
216
3.6.5 Recursive functions. ............................................,.......................................217
3.6.6 Generators and iterators
219
3.7 Object-oriented programming and classes.
3.7.1 The constructor
。鲁·垂垂。·。非
.224
3.7.2 Inheritance --Implementing a subclass
225
3.7.3 Classes and polymorphism
227
3.7.4 Recursive calls to methods
+·······4·
228
3.7.5 Class variables. class methods and static methods
230
3.7.5.1 Decorators for classmethod and staticmethod
233
Page7
A Python book
3.8 Additional and Advanced Topics……….……….………..234
3.8.1 Decorators and how to implement them.......... 234
3.8.1.1 Decorators with arguments
235
3.8. 1.2 Stacked decorators............................236
3.8.1.3 More help with decorators…….….….….….….….….…..….….238
3.8.2 Iterables
239
3.8.2.1 A few preliminaries on Iterables
239
3.8.2.2 More help with iterables..................................240
3.9 Applications and recipes
240
3.9.1 XML --SAX. minicom. elementtree. Lxml
24l
3.9.2 Relational database access
中··:·.:·*·
249
3.9.3 CSV--comma separated value files....................255
3.9. 4 YAML and Py YaML
春··。·音番
.256
3.9.5Json………………………………………………………………258
4 Part 4-- Generating Python bindings for XML
……260
4.1 Introduction
260
4.2 Generating the code....
·················
261
4.3 Using the generated code to parse and export an XML document......263
4.4 Some command line options you might want to know……………263
4.5 The graphical front-end
264
4.6 Adding application- specific behavior……
265
4.6.1 Implementing custom
4.6.2 Using the generated"API" from your application.……….……
266
4.6.3 A combined approach
267
4.7 Special situations and uses
269
4.7.1 Generic, type-independent processing.......269
4.7.1.1 Step l--generate the bindings...
270
4.7.1.2Step2- add application- specific code………………270
4.7. 1.3 Step 3 -- write a test/driver harness
274
4.7. 1.4 Step 4--run the test application
276
4. 8 Some hints
276
4.8.1 Children defined with maxoccurs greater than I
276
4.8.2 Children defined with simple numeric types
277
4.8.3 The type of an element' s character content.…………277
4.8 4 Constructors and thcir default valucs
··············:······:····4···········
277
A Python book
Preface
This book is a collection of materials that T've used when conducting Python training and
also materials from my Web site that are intended for sclf-instruction
You may prefer a machine readable copy of this book. You can find it in various formats
her
Html-Http:/www.davekuhlman.org/python_book_o1.html
Pdf--http:/www.davekuhlman.org/python_book_01pdf
eOdf/oPenofFice--Http://www.davekuhlman.org/python_book_01.odt
And, let me thank the students in my Python classes. Their questions and suggestions
were a great help in the preparation of these materials
g
A Python book
1 Part 1-- Beginning Python
11 introductions etc
Introductions
Practical matters restrooms, breakroom lunch and break times etc
Starting the Python interactive interpreter. Also, IPython and Idle
Running scripts
Editors--Choose an editor which you can configure so that it indents with 4 spaces, not
tab characters. For a list of editors for python, see
http://wiki.pythonorg/moin/pythonEditorsAfewpossibleeditors
Scite--http://www.scintilla.org/scite.html
MsWindowsonly--(1)textpad--http:www.textpad.com;(2)ultraedit
http://www.ultracdit.com
Jed--seehttp:/wwwjedsoft.org/jed/
Emacs--seehttp://www.gnu.org/software/emacs/and
http://www.xemacs.org/faq/xemacs-fag.html
Edit--requiresabitofcustomizationforPython--seehttp:/ljedit.org
.Vim--http://www.vim.org
.Geany--http:/www.geany.org/
And many more
Interactive interpreters
python
ipython
Idle
IDES - Also scc
http://en.wikipedia.org/wiki/list_ofintegrateD__development_environments_for_python
Py Win--MS Windows only. Available at
http:/sourceforge.net/projects/pywin32/
Wingide--seehttp:/wingware.com/wingide/
Eclipse--http:/cclipsc.org/.Thereisaplug-inthatsupportsPython
.Kdevelop--linux/kde--seehttp://www.kdevelop.org/.
Eric--linuxkdE?--sEehttp://eric-ide.python-projects.org/index.htmi
Emacs and scite will evaluate a python buffer within the editor
age
(系统自动生成,下载前可以参看下载内容)
下载文件列表
相关说明
- 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
- 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度。
- 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
- 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
- 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
- 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.