资源大小: 4.42MB
发布时间: 2013-01-16
文件格式: pdf
下载次数: 2
分享到:

下载地址:

下载地址1
(本站为飞网专业下载站,域名:down.cfei.net)

资源简介:

中文名: Python快速入门 (英文版)原名: The Quick Python Book,Second Edition作者: Vernon L.Ceder资源格式: PDF版本: 第二版出版社: Manning Publications Co.书号: 9781935182207发行时间: 2010年01月地区: 美国语言: 英文简介: 快速学习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. 目录: contentspreface xviiacknowledgments xviiiabout this book xxPART 1 STARTING OUT ................................................. 11 About Python 31.1 Why should I use Python? 31.2 What Python does well 4Python 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 7Python is not the fastest language 7 Python doesn’t have the■most libraries 8 Python doesn’t check variable types at■compile time 81.4 Why learn Python 3? 81.5 Summary 9viiviii CONTENTS2 Getting started 102.1 Installing Python 102.2 IDLE and the basic interactive mode 12The basic interactive mode 12 The IDLE integrated development■environment 13 Choosing between basic interactive mode and■IDLE 142.3 Using IDLE’s Python Shell window 142.4 Hello, world 152.5 Using the interactive prompt to explore Python 152.6 Summary 173 The Quick Python overview 183.1 Python synopsis 193.2 Built-in data types 19Numbers 19 Lists 21 Tuples 22 Strings 23■ ■ ■Dictionaries 24 Sets 24 File objects 25■ ■3.3 Control flow structures 25Boolean 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 293.5 Object-oriented programming 303.6 Summary 31PART 2 THE ESSENTIALS ............................................. 334 The absolute basics 354.1 Indentation and block structuring 354.2 Differentiating comments 374.3 Variables and assignments 374.4 Expressions 384.5 Strings 394.6 Numbers 40Built-in numeric functions 41 Advanced numeric■functions 41 Numeric computation 41 Complex■ ■numbers 41 Advanced complex-number functions 42■4.7 The None value 43ixCONTENTS4.8 Getting input from the user 434.9 Built-in operators 434.10 Basic Python style 434.11 Summary 445 Lists, tuples, and sets 455.1 Lists are like arrays 465.2 List indices 465.3 Modifying lists 485.4 Sorting lists 50Custom sorting 51 The sorted() function 52■5.5 Other common list operations 52List 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 555.7 Tuples 57Tuple basics 57 One-element tuples need a■comma 58 Packing and unpacking tuples 58■Converting between lists and tuples 605.8 Sets 60Set operations 60 Frozensets 61■5.9 Summary 626 Strings 636.1 Strings as sequences of characters 636.2 Basic string operations 646.3 Special characters and escape sequences 64Basic escape sequences 65 Numeric (octal and hexadecimal) and■Unicode escape sequences 65 Printing vs. evaluating strings■with special characters 666.4 String methods 67The 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 CONTENTS6.5 Converting from objects to strings 746.6 Using the format method 76The format method and positional parameters 76 The format■method and named parameters 76 Format specifiers 77■6.7 Formatting strings with % 77Using formatting sequences 78 Named parameters and■formatting sequences 786.8 Bytes 806.9 Summary 807 Dictionaries 817.1 What is a dictionary? 82Why dictionaries are called dictionaries 837.2 Other dictionary operations 837.3 Word counting 867.4 What can be used as a key? 867.5 Sparse matrices 887.6 Dictionaries as caches 887.7 Efficiency of dictionaries 897.8 Summary 898 Control flow 908.1 The while loop 90The break and continue statements 918.2 The if-elif-else statement 918.3 The for loop 92The 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 958.5 Statements, blocks, and indentation 968.6 Boolean values and expressions 99Most Python objects can be used as Booleans 99 Comparison and■Boolean operators 1008.7 Writing a simple program to analyze a text file 1018.8 Summary 102xiCONTENTS9 Functions 1039.1 Basic function definitions 1039.2 Function parameter options 105Positional parameters 105 Passing arguments by parameter■name 106 Variable numbers of arguments 107 Mixing■ ■argument-passing techniques 1089.3 Mutable objects as arguments 1089.4 Local, nonlocal, and global variables 1099.5 Assigning functions to variables 1119.6 lambda expressions 1119.7 Generator functions 1129.8 Decorators 1139.9 Summary 11410 Modules and scoping rules 11510.1 What is a module? 11510.2 A first module 11610.3 The import statement 11910.4 The module search path 119Where to place your own modules 12010.5 Private names in modules 12110.6 Library and third-party modules 12210.7 Python scoping rules and namespaces 12310.8 Summary 12811 Python programs 12911.1 Creating a very basic program 130Starting 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 13311.2 Making a script directly executable on UNIX 13511.3 Scripts on Mac OS X 13511.4 Script execution options in Windows 135Starting 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 CONTENTS11.5 Scripts on Windows vs. scripts on UNIX 13811.6 Programs and modules 14011.7 Distributing Python applications 145distutils 145 py2exe and py2app 145 Creating executable■ ■programs with freeze 14511.8 Summary 14612 Using the filesystem 14712.1 Paths and pathnames 148Absolute and relative paths 148 The current working■directory 149 Manipulating pathnames 150 Useful■ ■constants and functions 15312.2 Getting information about files 15412.3 More filesystem operations 15512.4 Processing all files in a directory subtree 15612.5 Summary 15713 Reading and writing files 15913.1 Opening files and file objects 15913.2 Closing files 16013.3 Opening files in write or other modes 16013.4 Functions to read and write text or binary data 161Using binary mode 16313.5 Screen input/output and redirection 16313.6 Reading structured binary data with the struct module 16513.7 Pickling objects into files 16713.8 Shelving objects 17013.9 Summary 17114 Exceptions 17214.1 Introduction to exceptions 173General philosophy of errors and exception handling 173 A more■formal definition of exceptions 175 User-defined exceptions 176■14.2 Exceptions in Python 176Types 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■xiiiCONTENTSExample: a disk-writing program in Python 182 Example:■exceptions in normal evaluation 183 Where to use■exceptions 18414.3 Using with 18414.4 Summary 18515 Classes and object-oriented programming 18615.1 Defining classes 187Using a class instance as a structure or record 18715.2 Instance variables 18815.3 Methods 18815.4 Class variables 190An oddity with class variables 19115.5 Static methods and class methods 192Static methods 192 Class methods 193■15.6 Inheritance 19415.7 Inheritance with class and instance variables 19615.8 Private variables and private methods 19715.9 Using @property for more flexible instance variables 19815.10 Scoping rules and namespaces for class instances 19915.11 Destructors and memory management 20315.12 Multiple inheritance 20715.13 Summary 20816 Graphical user interfaces 20916.1 Installing Tkinter 21016.2 Starting Tk and using Tkinter 21116.3 Principles of Tkinter 212Widgets 212 Named attributes 212 Geometry management■ ■and widget placement 21316.4 A simple Tkinter application 21416.5 Creating widgets 21516.6 Widget placement 21616.7 Using classes to manage Tkinter applications 21816.8 What else can Tkinter do? 219Event handling 220 Canvas and text widgets 221■xiv CONTENTS16.9 Alternatives to Tkinter 22116.10 Summary 222PART 3 ADVANCED LANGUAGE FEATURES ................... 22317 Regular expressions 22517.1 What is a regular expression? 22517.2 Regular expressions with special characters 22617.3 Regular expressions and raw strings 227Raw strings to the rescue 22817.4 Extracting matched text from strings 22917.5 Substituting text with regular expressions 23217.6 Summary 23318 Packages 23418.1 What is a package? 23418.2 A first example 23518.3 A concrete example 236Basic 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 24018.5 Proper use of packages 24118.6 Summary 24119 Data types as objects 24219.1 Types are objects, too 24219.2 Using types 24319.3 Types and user-defined classes 24319.4 Duck typing 24519.5 Summary 24620 Advanced object-oriented features 24720.1 What is a special method attribute? 24820.2 Making an object behave like a list 249The __getitem__ special method attribute 249 How it■works 250 Implementing full list functionality 251■xvCONTENTS20.3 Giving an object full list capability 25220.4 Subclassing from built-in types 254Subclassing list 254 Subclassing UserList 255■20.5 When to use special method attributes 25620.6 Metaclasses 25620.7 Abstract base classes 258Using abstract base classes for type checking 259 Creating■abstract base classes 260 Using the @abstractmethod and■@abstractproperty decorators 26020.8 Summary 262PART 4 WHERE CAN YOU GO FROM HERE? ................. 26321 Testing your code made easy(-er) 26521.1 Why you need to have tests 26521.2 The assert statement 266Python’s __debug__ variable 26621.3 Tests in docstrings: doctests 267Avoiding doctest traps 269 Tweaking doctests with■directives 269 Pros and cons of doctests 270■21.4 Using unit tests to test everything, every time 270Setting up and running a single test case 270 Running the■test 272 Running multiple tests 272 Unit tests vs.■ ■doctests 27321.5 Summary 27322 Moving from Python 2 to Python 3 27422.1 Porting from 2 to 3 274Steps in porting from Python 2.x to 3.x 27522.2 Testing with Python 2.6 and -3 27622.3 Using 2to3 to convert the code 27722.4 Testing and common problems 27922.5 Using the same code for 2 and 3 280Using Python 2.5 or earlier 280 Writing for Python 3.x and■converting back 28122.6 Summary 281xvi CONTENTS23 Using Python libraries 28223.1 “Batteries included”—the standard library 282Managing 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 28623.2 Moving beyond the standard library 28723.3 Adding more Python libraries 28723.4 Installing Python libraries using setup.py 288Installing under the home scheme 288 Other installation■options 28923.5 PyPI, a.k.a. “the Cheese Shop” 28923.6 Summary 28924 Network, web, and database programming 29024.1 Accessing databases in Python 291Using the sqlite3 database 29124.2 Network programming in Python 293Creating an instant HTTP server 293 Writing an HTTP■client 29424.3 Creating a Python web application 295Using the web server gateway interface 295 Using the wsgi■library to create a basic web app 295 Using frameworks to create■advanced web apps 29624.4 Sample project—creating a message wall 297Creating 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 304appendix 305index 323


飞网下载站,免费下载共享资料,内容涉及教育资源、专业资料、IT资源、娱乐生活、经济管理、办公文书、游戏资料等。