Contents

Preface

Acknowledgments

Part I: Core Python

1 Welcome to Python!

1.1. What Is Python?

1.2. Origins

1.3. Features

1.4. Downloading and Installing Python

1.5. Running Python

1.6. Python Documentation

1.7. Comparing Python

1.8. Other Implementations

1.9. Exercises

2 Getting Started

2.1. Program Output, the print Statement, and “Hello World!”

2.2. Program Input and the raw_input() Built-in Function

2.3. Comments

2.4. Operators

2.5. Variables and Assignment

2.6. Numbers

2.7. Strings

2.8. Lists and Tuples

2.9. Dictionaries

2.10. Code Blocks Use Indentation

2.11. if Statement

2.12. while Loop

2.13. for Loop and the range() Built-in Function

2.14. List Comprehensions

2.15. Files and the open() and file() Built-in Functions

2.16. Errors and Exceptions

2.17. Functions

2.18. Classes

2.19. Modules

2.20. Useful Functions

2.21. Exercises

3 Python Basics

3.1. Statements and Syntax

3.2. Variable Assignment

3.3. Identifiers

3.4. Basic Style Guidelines

3.5. Memory Management

3.6. First Python Programs

3.7. Related Modules/Developer Tools

3.8. Exercises

4 Python Objects

4.1. Python Objects

4.2. Standard Types

4.3. Other Built-in Types

4.4. Internal Types

4.5. Standard Type Operators

4.6. Standard Type Built-in Functions

4.7. Type Factory Functions

4.8. Categorizing the Standard Types

4.9. Unsupported Types

4.10. Exercises

5 Numbers

5.1. Introduction to Numbers

5.2. Integers

5.3. Double Precision Floating Point Numbers

5.4. Complex Numbers

5.5. Operators

5.6. Built-in and Factory Functions

5.7. Other Numeric Types

5.8. Related Modules

5.9. Exercises

6 Sequences: Strings, Lists, and Tuples

6.1. Sequences

6.2. Strings

6.3. Strings and Operators

6.4. String-Only Operators

6.5. Built-in Functions

6.6. String Built-in Methods

6.7. Special Features of Strings

6.8. Unicode

6.9. Related Modules

6.10. Summary of String Highlights

6.11. Lists

6.12. Operators

6.13. Built-in Functions

6.14. List Type Built-in Methods

6.15. Special Features of Lists

6.16. Tuples

6.17. Tuple Operators and Built-in Functions

6.18. Special Features of Tuples

6.19. Related Modules

6.20. *Copying Python Objects and Shallow and Deep Copies

6.21. Summary of Sequences

6.22. Exercises

7 Mapping and Set Types

7.1. Mapping Type: Dictionaries

7.2. Mapping Type Operators

7.3. Mapping Type Built-in and Factory Functions

7.4. Mapping Type Built-in Methods

7.5. Dictionary Keys

7.6. Set Types

7.7. Set Type Operators

7.8. Built-in Functions

7.9. Set Type Built-in Methods

7.10. Operator, Function/Method Summary Table for Set Types

7.11. Related Modules

7.12. Exercises

8 Conditionals and Loops

8.1. if Statement

8.2. else Statement

8.3. elif (aka else-if) Statement

8.4. Conditional Expressions (aka “the Ternary Operator”)

8.5. while Statement

8.6. for Statement

8.7. break Statement

8.8. continue Statement

8.9. pass Statement

8.10. else Statement ... Take Two

8.11. Iterators and the iter() Function

8.12. List Comprehensions

8.13. Generator Expressions

8.14. Related Modules

8.15. Exercises

9 Files and Input/Output

9.1. File Objects

9.2. File Built-in Functions [open() and file()]

9.3. File Built-in Methods

9.4. File Built-in Attributes

9.5. Standard Files

9.6. Command-Line Arguments

9.7. File System

9.8. File Execution

9.9. Persistent Storage Modules

9.10. Related Modules

9.11. Exercises

10 Errors and Exceptions

10.1. What Are Exceptions?

10.2. Exceptions in Python

10.3. Detecting and Handling Exceptions

10.4. Context Management

10.5. *Exceptions as Strings

10.6. Raising Exceptions

10.7. Assertions

10.8. Standard Exceptions

10.9. *Creating Exceptions

10.10. Why Exceptions (Now)?

10.11. Why Exceptions at All?

10.12. Exceptions and the sys Module

10.13. Related Modules

10.14. Exercises

11 Functions and Functional Programming

11.1. What Are Functions?

11.2. Calling Functions

11.3. Creating Functions

11.4. Passing Functions

11.5. Formal Arguments

11.6. Variable-Length Arguments

11.7. Functional Programming

11.8. Variable Scope

11.9. *Recursion

11.10. Generators

11.11. Exercises

12 Modules

12.1. What Are Modules?

12.2. Modules and Files

12.3. Namespaces

12.4. Importing Modules

12.5. Features of Module Import

12.6. Module Built-in Functions

12.7. Packages

12.8. Other Features of Modules

12.9. Related Modules

12.10. Exercises

13 Object-Oriented Programming

13.1. Introduction

13.2. Object-Oriented Programming

13.3. Classes

13.4. Class Attributes

13.5. Instances

13.6. Instance Attributes

13.7. Binding and Method Invocation

13.8. Static Methods and Class Methods

13.9. Composition

13.10. Subclassing and Derivation

13.11. Inheritance

13.12. Built-in Functions for Classes, Instances, and Other Objects

13.13. Customizing Classes with Special Methods

13.14. Privacy

13.15. *Delegation

13.16. Advanced Features of New-Style Classes ()

13.17. Related Modules and Documentation

13.18. Exercises

14 Execution Environment

14.1. Callable Objects

14.2. Code Objects

14.3. Executable Object Statements and Built-in Functions

14.4. Executing Other (Python) Programs

14.5. Executing Other (Non-Python) Programs

14.6. Restricted Execution

14.7. Terminating Execution

14.8. Miscellaneous Operating System Interface

14.9. Related Modules

14.10. Exercises

Part II: Advanced Topics

15 Regular Expressions

15.1. Introduction/Motivation

15.2. Special Symbols and Characters

15.3. REs and Python

15.4. Regular Expressions Example

15.5. Exercises

16 Network Programming

16.1. Introduction

16.2. Sockets: Communication Endpoints

16.3. Network Programming in Python

16.4. *SocketServer Module

16.5. Introduction to the Twisted Framework

16.6. Related Modules

16.7. Exercises

17 Internet Client Programming

17.1. What Are Internet Clients?

17.2. Transferring Files

17.3. Network News

17.4. Electronic Mail

17.5. Related Modules

17.6. Exercises

18 Multithreaded Programming

18.1. Introduction/Motivation

18.2. Threads and Processes

18.3. Python, Threads, and the Global Interpreter Lock

18.4. thread Module

18.5. threading Module

18.6. Related Modules

18.7. Exercises

19 GUI Programming

19.1. Introduction

19.2. Tkinter and Python Programming

19.3. Tkinter Examples

19.4. Brief Tour of Other GUIs

19.5. Related Modules and Other GUIs

19.6. Exercises

20 Web Programming

20.1. Introduction

20.2. Web Surfing with Python: Creating Simple Web Clients

20.3. Advanced Web Clients

20.4. CGI: Helping Web Servers Process Client Data

20.5. Building CGI Applications

20.6. Using Unicode with CGI

20.7. Advanced CGI

20.8. Web (HTTP) Servers

20.9. Related Modules

20.10. Exercises

21 Database Programming

21.1. Introduction

21.2. Python Database Application Programmer’s Interface (DB-API)

21.3. Object-Relational Managers (ORMs)

21.4. Related Modules

21.5. Exercises

22 Extending Python

22.1. Introduction/Motivation

22.2. Extending Python by Writing Extensions

22.3. Related Topics

22.4. Exercises

23 Miscellaneous

23.1. Web Services

23.2. Programming Microsoft Office with Win32 COM

23.3. Python and Java Programming with Jython

23.4. Exercises

Appendix A Answers to Selected Exercises

Appendix B Reference Tables

Appendix C Python 3: The Evolution of a Programming Language

Appendix D Migrating to Python 3 Starts with 2.6

Index

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset