[Wiki Books]Python_Programming

VIP免费
2025-02-27 0 0 856.75KB 159 页 5.9玖币
侵权投诉
Python Programming
Wikibooks.org
June 22, 2012
On the 28th of April 2012 the contents of the English as well as German Wikibooks and Wikipedia projects were
licensed under Creative Commons Attribution-ShareAlike 3.0 Unported license. An URI to this license is given
in the list of figures on page 149. If this document is a derived work from the contents of one of these projects
and the content was still licensed by the project under this license at the time of derivation this document has
to be licensed under the same, a similar or a compatible license, as stated in section 4b of the license. The
list of contributors is included in chapter Contributors on page 143. The licenses GPL, LGPL and GFDL are
included in chapter Licenses on page 153, since this book and/or parts of it may or may not be licensed under
one or more of these licenses, and thus require inclusion of these licenses. The licenses of the figures are given
in the list of figures on page 149. This PDF was generated by the L
A
T
E
X typesetting software. The L
A
T
E
X source
code is included as an attachment (
source.7z.txt
) in this PDF file. To extract the source from the PDF
file, we recommend the use of
http://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/
utility or clicking the paper clip attachment symbol on the lower left of your PDF Viewer, selecting
Save
Attachment
. After extracting it from the PDF file you have to rename it to
source.7z
. To uncompress
the resulting archive we recommend the use of
http://www.7-zip.org/
. The L
A
T
E
X source itself
was generated by a program written by Dirk Hünniger, which is freely available under an open source
license from
http://de.wikibooks.org/wiki/Benutzer:Dirk_Huenniger/wb2pdf
. This
distribution also contains a configured version of the
pdflatex
compiler with all necessary packages and
fonts needed to compile the L
A
T
E
X source included in this PDF file.
Contents
1 Overview 3
2 Getting Python 5
2.1 Python2vsPython3 ................................. 5
2.2 Installing Python in Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.3 InstallingPythononMac............................... 6
2.4 Installing Python on Unix environments . . . . . . . . . . . . . . . . . . . . . . . 6
2.5 KeepingUptoDate.................................. 8
3 Interactive mode 9
4 Creating Python programs 11
4.1 Hello,World! ..................................... 11
4.2 Exercises ....................................... 13
4.3 Notes ......................................... 13
5 Basic syntax 15
6 Data types 19
7 Numbers 21
8 Strings 23
8.1 Stringmanipulation.................................. 23
9 Lists 33
9.1 AboutlistsinPython ................................. 33
9.2 Listmethods...................................... 38
9.3 operators ....................................... 39
10 Dictionaries 41
10.1 About dictionaries in Python . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
11 Sets 43
12 Operators 49
12.1Basics......................................... 49
12.2Powers......................................... 49
12.3 Division and Type Conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
12.4Modulo ........................................ 50
12.5Negation........................................ 50
12.6AugmentedAssignment................................ 50
III
Contents
12.7Boolean ........................................ 51
12.8References....................................... 51
13 Flow control 53
14 Functions 59
15 Scoping 63
16 Exceptions 65
17 Input and output 69
17.1Input.......................................... 69
17.2Output......................................... 72
18 Modules 75
18.1ImportingaModule.................................. 75
18.2CreatingaModule .................................. 76
18.3Externallinks ..................................... 77
19 Classes 79
20 MetaClasses 95
21 Regular Expression 99
21.1Patternobjects..................................... 99
21.2Matchingandsearching................................ 100
21.3Replacing ....................................... 102
21.4Otherfunctions .................................... 102
21.5Externallinks ..................................... 103
22 GUI Programming 105
22.1Tkinter......................................... 105
22.2PyGTK ........................................ 106
22.3PyQt.......................................... 106
22.4wxPython ....................................... 106
22.5Dabo.......................................... 107
22.6pyFltk ......................................... 108
22.7OtherToolkits..................................... 108
23 Game Programming in Python 109
23.13DGameProgramming................................ 109
23.22DGameProgramming................................ 110
23.3SeeAlso........................................ 111
24 Sockets 113
24.1HTTPClient...................................... 113
24.2NTP/Sockets ..................................... 113
IV
Contents
25 Files 115
25.1FileI/O ........................................ 115
25.2TestingFiles...................................... 116
25.3CommonFileOperations............................... 117
26 Database Programming 119
26.1 Generic Database Connectivity using ODBC . . . . . . . . . . . . . . . . . . . . . 119
26.2 Postgres connection in Python . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
26.3 MySQL connection in Python . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
26.4SQLAlchemyinAction................................ 120
26.5Seealso ........................................ 120
26.6References....................................... 120
26.7Externallinks ..................................... 120
27 Web Page Harvesting 121
28 Threading 123
28.1Examples ....................................... 123
29 Extending with C 125
29.1UsingthePython/CAPI ............................... 125
29.2UsingSWIG...................................... 128
30 Extending with C++ 131
30.1AHelloWorldExample ............................... 131
30.2AnexamplewithCGAL ............................... 132
30.3 Handling Python objects and errors . . . . . . . . . . . . . . . . . . . . . . . . . . 133
31 WSGI web programming 135
32 WSGI Web Programming 137
32.1ExternalResources .................................. 137
33 References 139
33.1Languagereference.................................. 139
33.2Externallinks ..................................... 139
34 Authors 141
34.1 Authors of Python textbook . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
35 Contributors 143
List of Figures 149
36 Licenses 153
36.1 GNU GENERAL PUBLIC LICENSE . . . . . . . . . . . . . . . . . . . . . . . . 153
36.2 GNU Free Documentation License . . . . . . . . . . . . . . . . . . . . . . . . . . 154
36.3 GNU Lesser General Public License . . . . . . . . . . . . . . . . . . . . . . . . . 154
1
摘要:

PythonProgrammingWikibooks.orgJune22,2012Onthe28thofApril2012thecontentsoftheEnglishaswellasGermanWikibooksandWikipediaprojectswerelicensedunderCreativeCommonsAttribution-ShareAlike3.0Unportedlicense.AnURItothislicenseisgiveninthelistofguresonpage149.Ifthisdocumentisaderivedworkfromthecontentsofone...

展开>> 收起<<
[Wiki Books]Python_Programming.pdf

共159页,预览5页

还剩页未读, 继续阅读

声明:本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。玖贝云文库仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知玖贝云文库,我们立即给予删除!
分类:计算机 价格:5.9玖币 属性:159 页 大小:856.75KB 格式:PDF 时间:2025-02-27

开通VIP享超值会员特权

  • 多端同步记录
  • 高速下载文档
  • 免费文档工具
  • 分享文档赚钱
  • 每日登录抽奖
  • 优质衍生服务
/ 159
客服
关注