1. Trang chủ
  2. » Tất cả

Python.Essential.Reference.(2009),.4Ed

745 310 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Cấu trúc

  • Table of Contents

  • Introduction

  • I: The Python Language

    • 1 A Tutorial Introduction

      • Running Python

      • Variables and Arithmetic Expressions

      • Conditionals

      • File Input and Output

      • Strings

      • Lists

      • Tuples

      • Sets

      • Dictionaries

      • Iteration and Looping

      • Functions

      • Generators

      • Coroutines

      • Objects and Classes

      • Exceptions

      • Modules

      • Getting Help

    • 2 Lexical Conventions and Syntax

      • Line Structure and Indentation

      • Identifiers and Reserved Words

      • Numeric Literals

      • String Literals

      • Containers

      • Operators, Delimiters, and Special Symbols

      • Documentation Strings

      • Decorators

      • Source Code Encoding

    • 3 Types and Objects

      • Terminology

      • Object Identity and Type

      • Reference Counting and Garbage Collection

      • References and Copies

      • First-Class Objects

      • Built-in Types for Representing Data

      • Built-in Types for Representing Program Structure

      • Built-in Types for Interpreter Internals

      • Object Behavior and Special Methods

    • 4 Operators and Expressions

      • Operations on Numbers

      • Operations on Sequences

      • String Formatting

      • Advanced String Formatting

      • Operations on Dictionaries

      • Operations on Sets

      • Augmented Assignment

      • The Attribute (.) Operator

      • The Function Call () Operator

      • Conversion Functions

      • Boolean Expressions and Truth Values

      • Object Equality and Identity

      • Order of Evaluation

      • Conditional Expressions

    • 5 Program Structure and Control Flow

      • Program Structure and Execution

      • Conditional Execution

      • Loops and Iteration

      • Exceptions

      • Context Managers and the with Statement

      • Assertions and __debug__

    • 6 Functions and Functional Programming

      • Functions

      • Parameter Passing and Return Values

      • Scoping Rules

      • Functions as Objects and Closures

      • Decorators

      • Generators and yield

      • Coroutines and yield Expressions

      • Using Generators and Coroutines

      • List Comprehensions

      • Generator Expressions

      • Declarative Programming

      • The lambda Operator

      • Recursion

      • Documentation Strings

      • Function Attributes

      • eval(), exec(), and compile()

    • 7 Classes and Object-Oriented Programming

      • The class Statement

      • Class Instances

      • Scoping Rules

      • Inheritance

      • Polymorphism Dynamic Binding and Duck Typing

      • Static Methods and Class Methods

      • Properties

      • Descriptors

      • Data Encapsulation and Private Attributes

      • Object Memory Management

      • Object Representation and Attribute Binding

      • __slots__

      • Operator Overloading

      • Types and Class Membership Tests

      • Abstract Base Classes

      • Metaclasses

      • Class Decorators

    • 8 Modules, Packages, and Distribution

      • Modules and the import Statement

      • Importing Selected Symbols from a Module

      • Execution as the Main Program

      • The Module Search Path

      • Module Loading and Compilation

      • Module Reloading and Unloading

      • Packages

      • Distributing Python Programs and Libraries

      • Installing Third-Party Libraries

    • 9 Input and Output

      • Reading Command-Line Options

      • Environment Variables

      • Files and File Objects

      • Standard Input, Output, and Error

      • The print Statement

      • The print() Function

      • Variable Interpolation in Text Output

      • Generating Output

      • Unicode String Handling

      • Unicode I/O

      • Object Persistence and the pickle Module

    • 10 Execution Environment

      • Interpreter Options and Environment

      • Interactive Sessions

      • Launching Python Applications

      • Site Configuration Files

      • Per-user Site Packages

      • Enabling Future Features

      • Program Termination

    • 11 Testing, Debugging, Profiling, and Tuning

      • Documentation Strings and the doctest Module

      • Unit Testing and the unittest Module

      • The Python Debugger and the pdb Module

      • Program Profiling

      • Tuning and Optimization

  • II: The Python Library

    • 12 Built-In Functions and Exceptions

      • Built-in Functions and Types

      • Built-In Exceptions

      • Built-In Warnings

      • future_builtins

    • 13 Python Runtime Services

      • atexit

      • copy

      • gc

      • inspect

      • marshal

      • pickle

      • sys

      • traceback

      • types

      • warnings

      • weakref

    • 14 Mathematics

      • decimal

      • fractions

      • math

      • numbers

      • random

    • 15 Data Structures, Algorithms, and Code Simplification

      • abc

      • array

      • bisect

      • collections

      • contextlib

      • functools

      • heapq

      • itertools

      • operator

    • 16 String and Text Handling

      • codecs

      • re

      • string

      • struct

      • unicodedata

    • 17 Python Database Access

      • Relational Database API Specification

      • sqlite3 Module

      • DBM-Style Database Modules

      • shelve Module

    • 18 File and Directory Handling

      • bz2

      • filecmp

      • fnmatch

      • glob

      • gzip

      • shutil

      • tarfile

      • tempfile

      • zipfile

      • zlib

    • 19 Operating System Services

      • commands

      • configParser, Configparser

      • datetime

      • errno

      • fcntl

      • io

      • logging

      • mmap

      • msvcrt

      • optparse

      • os

      • os.path

      • signal

      • subprocess

      • time

      • winreg

    • 20 Threads and Concurrency

      • Basic Concepts

      • Concurrent Programming and Python

      • multiprocessing

      • threading

      • queue, Queue

      • Coroutines and Microthreading

    • 21 Network Programming and Sockets

      • Network Programming Basics

      • asynchat

      • asyncore

      • select

      • socket

      • ssl

      • SocketServer

    • 22 Internet Application Programming

      • ftplib

      • http Package

      • smtplib

      • urllib Package

      • xmlrpc Package

    • 23 Web Programming

      • cgi

      • cgitb

      • wsgiref

      • webbrowser

    • 24 Internet Data Handling and Encoding

      • base64

      • binascii

      • csv

      • email Package

      • hashlib

      • hmac

      • HTMLParser

      • json

      • mimetypes

      • quopri

      • xml Package

    • 25 Miscellaneous Library Modules

      • Python Services

      • String Processing

      • Operating System Modules

      • Network

      • Internet Data Handling

      • Internationalization

      • Multimedia Services

      • Miscellaneous

  • III: Extending and Embedding

    • 26 Extending and Embedding Python

      • Extension Modules

      • Embedding the Python Interpreter

      • ctypes

      • Advanced Extending and Embedding

      • Jython and IronPython

  • Appendix: Python 3

    • Who Should Be Using Python 3?

    • New Language Features

      • Source Code Encoding and Identifiers

      • Set Literals

      • Set and Dictionary Comprehensions

      • Extended Iterable Unpacking

      • Nonlocal Variables

      • Function Annotations

      • Keyword-Only Arguments

      • Ellipsis as an Expression

      • Chained Exceptions

      • Improved super()

      • Advanced Metaclasses

    • Common Pitfalls

      • Text Versus Bytes

      • New I/O System

      • print() and exec() Functions

      • Use of Iterators and Views

      • Integers and Integer Division

      • Comparisons

      • Iterators and Generators

      • File Names, Arguments, and Environment Variables

      • Library Reorganization

      • Absolute Imports

    • Code Migration and 2to3

      • Porting Code to Python 2.6

      • Providing Test Coverage

      • Using the 2to3 Tool

      • A Practical Porting Strategy

      • Simultaneous Python 2 and Python 3 Support

      • Participate

  • Index

    • A

    • B

    • C

    • D

    • E

    • F

    • G

    • H

    • I

    • J

    • K

    • L

    • M

    • N

    • O

    • P

    • Q

    • R

    • S

    • T

    • U

    • V

    • W

    • X

    • Y

    • Z

Nội dung

From the Library of Lee Bogdanoff Download at WoweBook.Com Python ESSENTIAL REFERENCE Fourth Edition From the Library of Lee Bogdanoff Download at WoweBook.Com Developer’s Library ESSENTIAL REFERENCES FOR PROGRAMMING PROFESSIONALS Developer’s Library books are designed to provide practicing programmers with unique, high-quality references and tutorials on the programming languages and technologies they use in their daily work All books in the Developer’s Library are written by expert technology practitioners who are especially skilled at organizing and presenting information in a way that’s useful for other programmers Key titles include some of the best, most widely acclaimed books within their topic areas: PHP and MySQL Web Development Python Essential Reference Luke Welling & Laura Thomson ISBN 978-0-672-32916-6 David Beazley ISBN-13: 978-0-672-32862-6 MySQL Programming in Objective-C Paul DuBois ISBN-13: 978-0-672-32938-8 Stephen G Kochan ISBN-13: 978-0-321-56615-7 Linux Kernel Development PostgreSQL Robert Love ISBN-13: 978-0-672-32946-3 Korry Douglas ISBN-13: 978-0-672-33015-5 Developer’s Library books are available at most retail and online bookstores, as well as by subscription from Safari Books Online at safari.informit.com Developer’s Library informit.com/devlibrary From the Library of Lee Bogdanoff Download at WoweBook.Com Python ESSENTIAL REFERENCE Fourth Edition David M Beazley Upper Saddle River, NJ • Boston • Indianapolis • San Francisco New York • Toronto • Montreal • London • Munich • Paris • Madrid Cape Town • Sydney • Tokyo • Singapore • Mexico City From the Library of Lee Bogdanoff Download at WoweBook.Com Acquisitions Editor Mark Taber Python Essential Reference Fourth Edition Copyright © 2009 by Pearson Education, Inc All rights reserved No part of this book shall be reproduced, stored in a retrieval system, or transmitted by any means, electronic, mechanical, photocopying, recording, or otherwise, without written permission from the publisher No patent liability is assumed with respect to the use of the information contained herein Although every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions Nor is any liability assumed for damages resulting from the use of the information contained herein Development Editor Michael Thurston Managing Editor Patrick Kanouse Project Editor Seth Kerney Copy Editor Lisa Thibault ISBN-13: 978-0-672-32978-4 ISBN-10: 0-672-32978-6 Indexer David Beazley Printed in the United States of America Proofreader Megan Wade First Printing June 2009 Library of Congress Cataloging-in-Publication data is on file Trademarks All terms mentioned in this book that are known to be trademarks or service marks have been appropriately capitalized Addison-Wesley cannot attest to the accuracy of this information Use of a term in this book should not be regarded as affecting the validity of any trademark or service mark Warning and Disclaimer Every effort has been made to make this book as complete and as accurate as possible, but no warranty or fitness is implied The information provided is on an “as is” basis The author and the publisher shall have neither liability nor responsibility to any person or entity with respect to any loss or damages arising from the information contained in this book Technical Editors Noah Gift Kurt Grandis Publishing Coordinator Vanessa Evans Book Designer Gary Adair Compositor Bronkella Publishing Bulk Sales Addison-Wesley offers excellent discounts on this book when ordered in quantity for bulk purchases or special sales For more information, please contact U.S Corporate and Government Sales 1-800-382-3419 corpsales@pearsontechgroup.com For sales outside of the U.S., please contact International Sales international@pearson.com To register this product and gain access to bonus content, go to www.informit.com/register to sign in and enter the ISBN After you register the product, a link to the additional content will be listed on your Account page, under Registered Products From the Library of Lee Bogdanoff Download at WoweBook.Com ❖ For Paula,Thomas., and his brother on the way ❖ From the Library of Lee Bogdanoff Download at WoweBook.Com Contents at a Glance Introduction Part I: The Python Language A Tutorial Introduction Lexical Conventions and Syntax Types and Objects 25 33 Operators and Expressions 65 Program Structure and Control Flow 81 Functions and Functional Programming 93 Classes and Object-Oriented Programming Modules, Packages, and Distribution Input and Output 117 143 157 10 Execution Environment 173 11 Testing, Debugging, Profiling, and Tuning 181 Part II: The Python Library 12 Built-In Functions 201 13 Python Runtime Services 14 Mathematics 219 243 15 Data Structures, Algorithms, and Code Simplification 16 String and Text Handling 277 17 Python Database Access 297 18 File and Directory Handling 313 19 Operating System Services 331 20 Threads and Concurrency 413 21 Network Programming and Sockets 22 Internet Application Programming 23 Web Programming 257 449 497 531 24 Internet Data Handling and Encoding 25 Miscellaneous Library Modules 545 585 Part III: Extending and Embedding 26 Extending and Embedding Python Appendix: Python Index 591 621 639 From the Library of Lee Bogdanoff Download at WoweBook.Com Table of Contents Introduction I: The Python Language A Tutorial Introduction Running Python 5 Variables and Arithmetic Expressions Conditionals File Input and Output Strings Lists 10 11 12 Tuples Sets 14 15 Dictionaries 16 Iteration and Looping Functions 17 18 Generators 19 Coroutines 20 Objects and Classes Exceptions Modules 21 22 23 Getting Help 24 Lexical Conventions and Syntax 25 Line Structure and Indentation 25 Identifiers and Reserved Words Numeric Literals String Literals Containers 26 26 27 29 Operators, Delimiters, and Special Symbols Documentation Strings Decorators 30 30 30 Source Code Encoding Types and Objects Terminology 33 31 33 Object Identity and Type 33 Reference Counting and Garbage Collection References and Copies 34 35 From the Library of Lee Bogdanoff Download at WoweBook.Com viii Contents First-Class Objects 36 Built-in Types for Representing Data The None Type 38 Numeric Types 38 Sequence Types 39 Mapping Types Set Types 37 44 46 Built-in Types for Representing Program Structure Callable Types 47 Classes, Types, and Instances Modules 50 50 Built-in Types for Interpreter Internals Code Objects 52 Traceback Objects 52 Generator Objects 53 Slice Objects 51 51 Frame Objects 53 Ellipsis Object 54 Object Behavior and Special Methods Object Creation and Destruction Object String Representation 54 54 55 Object Comparison and Ordering Type Checking 56 57 Attribute Access 57 Attribute Wrapping and Descriptors Sequence and Mapping Methods Iteration 47 58 58 59 Mathematical Operations Callable Interface 60 62 Context Management Protocol Object Inspection and dir() 62 63 Operators and Expressions 65 Operations on Numbers 65 Operations on Sequences String Formatting 67 70 Advanced String Formatting Operations on Dictionaries Operations on Sets 72 74 75 Augmented Assignment 75 From the Library of Lee Bogdanoff Download at WoweBook.Com Contents The Attribute (.) Operator 76 The Function Call () Operator Conversion Functions 76 76 Boolean Expressions and Truth Values Object Equality and Identity Order of Evaluation 77 78 78 Conditional Expressions 79 Program Structure and Control Flow Program Structure and Execution 81 Conditional Execution 81 81 Loops and Iteration Exceptions 82 84 Built-in Exceptions 86 Defining New Exceptions 88 Context Managers and the with Statement Assertions and _ _debug_ _ Parameter Passing and Return Values Scoping Rules 93 95 96 Functions as Objects and Closures 98 101 Generators and yield 102 Coroutines and yield Expressions 104 Using Generators and Coroutines 106 List Comprehensions 108 Generator Expressions 109 Declarative Programming The lambda Operator Recursion 89 91 Functions and Functional Programming Functions 93 Decorators 110 112 112 Documentation Strings Function Attributes 113 114 eval(), exec(), and compile() 115 Classes and Object-Oriented Programming The class Statement 117 Class Instances Scoping Rules Inheritance ix 117 118 118 119 From the Library of Lee Bogdanoff

Ngày đăng: 13/04/2019, 01:45