Core Python Programming

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

Praise for Core Python Programming "The long-awaited second edition of Wesley Chun's Core Python Programming proves to be well worth the wait--its deep and broad coverage and useful exercises will help readers learn and practice good Python." --Alex Martelli, author of Python in a Nutshell and editor of Python Cookbook "There has been lot of good buzz around Wesley Chun's Core Python Programming. It turns out that all the buzz is well earned. I think this is the best book currently available for learning Python. I would recommend Chun's book over Learning Python (O'Reilly), Programming Python (O'Reilly), or The Quick Python Book (Manning)." --David Mertz, Ph.D., IBM DeveloperWorks(R) "I have been doing a lot of research [on] Python for the past year and have seen a number of positive reviews of your book. The sentiment expressed confirms the opinion that Core Python Programming is now considered the standard introductory text." --Richard Ozaki, Lockheed Martin "Finally, a book good enough to be both a textbook and a reference on the Python language now exists." --Michael Baxter, Linux Journal "Very well written. It is the clearest, friendliest book I have come across yet for explaining Python, and putting it in a wider context. It does not presume a large amount of other experience. It does go into some important Python topics carefully and in depth. Unlike too many beginner books, it never condescends or tortures the reader with childish hide-and-seek prose games. [It] sticks to gaining a solid grasp of Python syntax and structure." --http: //python.org bookstore Web site "[If ] I could only own one Python book, it would be Core Python Programming by Wesley Chun. This book manages to cover more topics in more depth than Learning Python but includes it all in one book that also more than adequately covers the core language. [If] you are in the market for just one book about Python, I recommend this book. You will enjoy reading it, including its wry programmer's wit. More importantly, you will learn Python. Even more importantly, you will find it invaluable in helping you in your day-to-day Python programming life. Well done, Mr. Chun!" --Ron Stephens, Python Learning Foundation "I think the best language for beginners is Python, without a doubt. My favorite book is Core Python Programming." --s003apr, MP3Car.com Forums "Personally, I really like Python. It's simple to learn, completely intuitive, amazingly flexible, and pretty darned fast. Python has only just started to claim mindshare in the Windows world, but look for it to start gaining lots of support as people discover it. To learn Python, I'd start with Core Python Programming by Wesley Chun." --Bill Boswell, MCSE, Microsoft Certified Professional Magazine Online "If you learn well from books, I suggest Core Python Programming. It is by far the best I've found. I'm a Python newbie as well and in three months time I've been able to implement Python in projects at work (automating MSOffice, SQL DB stuff, etc.)." --ptonman, Dev Shed Forums "Python is simply a beautiful language. It's easy to learn, it's cross-platform, and it works. It has achieved many of the technical goals that Java strives for. A one-sentence description of Python would be: 'All other languages appear to have evolved over time--but Python was designed.' And it was designed well. Unfortunately, there aren't a large number of books for Python. The best one I've run across so far is Core Python Programming." --Chris Timmons, C. R. Timmons Consulting "If you like the Prentice Hall Core series, another good full-blown treatment to consider would be Core Python Programming. It addresses in elaborate concrete detail many practical topics that get little, if any, coverage in other books." --Mitchell L Model, MLM Consulting "Core Python Programming is an amazingly easy read! The liberal use of examples helps clarify some of the more subtle points of the language. And the comparisons to languages with which I'm already familiar (C/C++/Java) get you programming in record speed." --Michael Santos, Ph.D., Green Hills Software The Complete Developer's Guide to Python New to Python? The definitive guide to Python development for experienced programmers Covers core language features thoroughly, including those found in the latest Python releases--learn more than just the syntax! Learn advanced topics such as regular expressions, networking, multithreading, GUI, Web/CGI, and Python extensions Includes brand-new material on databases, Internet clients, Java/Jython, and Microsoft Office, plus Python 2.6 and 3 Presents hundreds of code snippets, interactive examples, and practical exercises to strengthen your Python skills Python is an agile, robust, expressive, fully object-oriented, extensible, and scalable programming language. It combines the power of compiled languages with the simplicity and rapid development of scripting languages. In Core Python Programming, Second Edition , leading Python developer and trainer Wesley Chun helps you learn Python quickly and comprehensively so that you can immediately succeed with any Python project. Using practical code examples, Chun introduces all the fundamentals of Python programming: syntax, objects and memory management, data types, operators, files and I/O, functions, generators, error handling and exceptions, loops, iterators, functional programming, object-oriented programming and more. After you learn the core fundamentals of Python, he shows you what you can do with your new skills, delving into advanced topics, such as regular expressions, networking programming with sockets, multithreading, GUI development, Web/CGI programming and extending Python in C. This edition reflects major enhancements in the Python 2.x series, including 2.6 and tips for migrating to 3. It contains new chapters on database and Internet client programming, plus coverage of many new topics, including new-style classes, Java and Jython, Microsoft Office (Win32 COM Client) programming, and much more. Learn professional Python style, best practices, and good programming habits Gain a deep understanding of Python's objects and memory model as well as its OOP features, including those found in Python's new-style classes Build more effective Web, CGI, Internet, and network and other client/server applications Learn how to develop your own GUI applications using Tkinter and other toolkits available for Python Improve the performance of your Python applications by writing extensions in C and other languages, or enhance I/O-bound applications by using multithreading Learn about Python's database API and how to use a variety of database systems with Python, including MySQL, Postgres, and SQLite Features appendices on Python 2.6 & 3, including tips on migrating to the next generation! Core Python Programming delivers Systematic, expert coverage of Python's core features Powerful insights for developing complex applications Easy-to-use tables and charts detailing Python modules, operators, functions, and methods Dozens of professional-quality code examples, from quick snippets to full-fledged applications

Author(s): Wesley J. Chun
Edition: 2
Publisher: Prentice Hall
Year: 2006

Language: English
Pages: 1100

0132269937
Core Python Programming, Second Edition
Table of Contents
Copyright
Praise for Core Python Programming
Prentice Hall Core Series
Preface
Acknowledgments
Part I:  Core Python
Chapter 1.  Welcome to Python!
Section 1.1.  What Is Python?
Section 1.2.  Origins
Section 1.3.  Features
Section 1.4.  Downloading and Installing Python
Section 1.5.  Running Python
Section 1.6.  Python Documentation
Section 1.7.  Comparing Python
Section 1.8.  Other Implementations
Section 1.9.  Exercises
Chapter 2.  Getting Started
Section 2.1.  Program Output, the print Statement, and "Hello World!"
Section 2.2.  Program Input and the raw_input()Built-in Function
Section 2.3.  Comments
Section 2.4.  Operators
Section 2.5.  Variables and Assignment
Section 2.6.  Numbers
Section 2.7.  Strings
Section 2.8.  Lists and Tuples
Section 2.9.  Dictionaries
Section 2.10.  Code Blocks Use Indentation
Section 2.11.  if Statement
Section 2.12.  while Loop
Section 2.13.  for Loop and the range() Built-in Function
Section 2.14.  List Comprehensions
Section 2.15.  Files and the open() and file() Built-in Functions
Section 2.16.  Errors and Exceptions
Section 2.17.  Functions
Section 2.18.  Classes
Section 2.19.  Modules
Section 2.20.  Useful Functions
Section 2.21.  Exercises
Chapter 3.  Python Basics
Section 3.1.  Statements and Syntax
Section 3.2.  Variable Assignment
Section 3.3.  Identifiers
Section 3.4.  Basic Style Guidelines
Section 3.5.  Memory Management
Section 3.6.  First Python Programs
Section 3.7.  Related Modules/Developer Tools
Section 3.8.  Exercises
Chapter 4.  Python Objects
Section 4.1.  Python Objects
Section 4.2.  Standard Types
Section 4.3.  Other Built-in Types
Section 4.4.  Internal Types
Section 4.5.  Standard Type Operators
Section 4.6.  Standard Type Built-in Functions
Section 4.7.  Type Factory Functions
Section 4.8.  Categorizing the Standard Types
Section 4.9.  Unsupported Types
Section 4.10.  Exercises
Chapter 5.  Numbers
Section 5.1.  Introduction to Numbers
Section 5.2.  Integers
Section 5.3.  Double Precision Floating Point Numbers
Section 5.4.  Complex Numbers
Section 5.5.  Operators
Section 5.6.  Built-in and Factory Functions
Section 5.7.  Other Numeric Types
Section 5.8.  Related Modules
Section 5.9.  Exercises
Chapter 6.  Sequences: Strings, Lists, and Tuples
Section 6.1.  Sequences
Section 6.2.  Strings
Section 6.3.  Strings and Operators
Section 6.4.  String-Only Operators
Section 6.5.  Built-in Functions
Section 6.6.  String Built-in Methods
Section 6.7.  Special Features of Strings
Section 6.8.  Unicode
Section 6.9.  Related Modules
Section 6.10.  Summary of String Highlights
Section 6.11.  Lists
Section 6.12.  Operators
Section 6.13.  Built-in Functions
Section 6.14.  List Type Built-in Methods
Section 6.15.  Special Features of Lists
Section 6.16.  Tuples
Section 6.17.  Tuple Operators and Built-in Functions
Section 6.18.  Special Features of Tuples
Section 6.19.  Related Modules
Section 6.20.  *Copying Python Objects and Shallow and Deep Copies
Section 6.21.  Summary of Sequences
Section 6.22.  Exercises
Chapter 7.  Mapping and Set Types
Section 7.1.  Mapping Type: Dictionaries
Section 7.2.  Mapping Type Operators
Section 7.3.  Mapping Type Built-in and Factory Functions
Section 7.4.  Mapping Type Built-in Methods
Section 7.5.  Dictionary Keys
Section 7.6.  Set Types
Section 7.7.  Set Type Operators
Section 7.8.  Built-in Functions
Section 7.9.  Set Type Built-in Methods
Section 7.10.  Operator, Function/Method Summary Table for Set Types
Section 7.11.  Related Modules
Section 7.12.  Exercises
Chapter 8.  Conditionals and Loops
Section 8.1.  if Statement
Section 8.2.  else Statement
Section 8.3.  elif (aka else-if) Statement
Section 8.4.  Conditional Expressions (aka "the Ternary Operator")
Section 8.5.  while Statement
Section 8.6.  for Statement
Section 8.7.  break Statement
Section 8.8.  continue Statement
Section 8.9.  pass Statement
Section 8.10.  else Statement ... Take Two
Section 8.11.  Iterators and the iter() Function
Section 8.12.  List Comprehensions
Section 8.13.  Generator Expressions
Section 8.14.  Related Modules
Section 8.15.  Exercises
Chapter 9.  Files and Input/Output
Section 9.1.  File Objects
Section 9.2.  File Built-in Functions [open() and file()]
Section 9.3.  File Built-in Methods
Section 9.4.  File Built-in Attributes
Section 9.5.  Standard Files
Section 9.6.  Command-Line Arguments
Section 9.7.  File System
Section 9.8.  File Execution
Section 9.9.  Persistent Storage Modules
Section 9.10.  Related Modules
Section 9.11.  Exercises
Chapter 10.  Errors and Exceptions
Section 10.1.  What Are Exceptions?
Section 10.2.  Exceptions in Python
Section 10.3.  Detecting and Handling Exceptions
Section 10.4.  Context Management
Section 10.5.  *Exceptions as Strings
Section 10.6.  Raising Exceptions
Section 10.7.  Assertions
Section 10.8.  Standard Exceptions
Section 10.9.  *Creating Exceptions
Section 10.10.  Why Exceptions (Now)?
Section 10.11.  Why Exceptions at All?
Section 10.12.  Exceptions and the sys Module
Section 10.13.  Related Modules
Section 10.14.  Exercises
Chapter 11.  Functions and Functional Programming
Section 11.1.  What Are Functions?
Section 11.2.  Calling Functions
Section 11.3.  Creating Functions
Section 11.4.  Passing Functions
Section 11.5.  Formal Arguments
Section 11.6.  Variable-Length Arguments
Section 11.7.  Functional Programming
Section 11.8.  Variable Scope
Section 11.9.  *Recursion
Section 11.10.  Generators
Section 11.11.  Exercises
Chapter 12.  Modules
Section 12.1.  What Are Modules?
Section 12.2.  Modules and Files
Section 12.3.  Namespaces
Section 12.4.  Importing Modules
Section 12.5.  Features of Module Import
Section 12.6.  Module Built-in Functions
Section 12.7.  Packages
Section 12.8.  Other Features of Modules
Section 12.9.  Related Modules
Section 12.10.  Exercises
Chapter 13.  Object-Oriented Programming
Section 13.1.  Introduction
Section 13.2.  Object-Oriented Programming
Section 13.3.  Classes
Section 13.4.  Class Attributes
Section 13.5.  Instances
Section 13.6.  Instance Attributes
Section 13.7.  Binding and Method Invocation
Section 13.8.  Static Methods and Class Methods
Section 13.9.  Composition
Section 13.10.  Subclassing and Derivation
Section 13.11.  Inheritance
Section 13.12.  Built-in Functions for Classes, Instances, and Other Objects
Section 13.13.  Customizing Classes with Special Methods
Section 13.14.  Privacy
Section 13.15.  *Delegation
Section 13.16.  Advanced Features of New-Style Classes (Python 2.2+)
Section 13.17.  Related Modules and Documentation
Section 13.18.  Exercises
Chapter 14.  Execution Environment
Section 14.1.  Callable Objects
Section 14.2.  Code Objects
Section 14.3.  Executable Object Statements and Built-in Functions
Section 14.4.  Executing Other (Python) Programs
Section 14.5.  Executing Other (Non-Python) Programs
Section 14.6.  Restricted Execution
Section 14.7.  Terminating Execution
Section 14.8.  Miscellaneous Operating System Interface
Section 14.9.  Related Modules
Section 14.10.  Exercises
Part II:  Advanced Topics
Chapter 15.  Regular Expressions
Section 15.1.  Introduction/Motivation
Section 15.2.  Special Symbols and Characters
Section 15.3.  REs and Python
Section 15.4.  Regular Expressions Example
Section 15.5.  Exercises
Chapter 16.  Network Programming
Section 16.1.  Introduction
Section 16.2.  Sockets: Communication Endpoints
Section 16.3.  Network Programming in Python
Section 16.4.  *SocketServer Module
Section 16.5.  *Introduction to the Twisted Framework
Section 16.6.  Related Modules
Section 16.7.  Exercises
Chapter 17.  Internet Client Programming
Section 17.1.  What Are Internet Clients?
Section 17.2.  Transferring Files
Section 17.3.  Network News
Section 17.4.  Electronic Mail
Section 17.5.  Related Modules
Section 17.6.  Exercises
Chapter 18.  Multithreaded Programming
Section 18.1.  Introduction/Motivation
Section 18.2.  Threads and Processes
Section 18.3.  Python, Threads, and the Global Interpreter Lock
Section 18.4.  thread Module
Section 18.5.  threading Module
Section 18.6.  Related Modules
Section 18.7.  Exercises
Chapter 19.  GUI Programming
Section 19.1.  Introduction
Section 19.2.  Tkinter and Python Programming
Section 19.3.  Tkinter Examples
Section 19.4.  Brief Tour of Other GUIs
Section 19.5.  Related Modules and Other GUIs
Section 19.6.  Exercises
Chapter 20.  Web Programming
Section 20.1.  Introduction
Section 20.2.  Web Surfing with Python: Creating Simple Web Clients
Section 20.3.  Advanced Web Clients
Section 20.4.  CGI: Helping Web Servers Process Client Data
Section 20.5.  Building CGI Applications
Section 20.6.  Using Unicode with CGI
Section 20.7.  Advanced CGI
Section 20.8.  Web (HTTP) Servers
Section 20.9.  Related Modules
Section 20.10.  Exercises
Chapter 21.  Database Programming
Section 21.1.  Introduction
Section 21.2.  Python Database Application Programmer's Interface (DB-API)
Section 21.3.  Object-Relational Managers (ORMs)
Section 21.4.  Related Modules
Section 21.5.  Exercises
Chapter 22.  Extending Python
Section 22.1.  Introduction/Motivation
Section 22.2.  Extending Python by Writing Extensions
Section 22.3.  Related Topics
Section 22.4.  Exercises
Chapter 23.  Miscellaneous
Section 23.1.  Web Services
Section 23.2.  Programming Microsoft Office with Win32 COM
Section 23.3.  Python and Java Programming with Jython
Section 23.4.  Exercises
Appendix A.  Answers to Selected Exercises
Chapter 2
Chapter 3
Chapter 4
Chapter 5
Chapter 6
Chapter 7
Chapter 8
Chapter 9
Chapter 10
Chapter 11
Chapter 12
Chapter 13
Chapter 14
Chapter 15
Chapter 16
Chapter 17
Chapter 18
Chapter 19
Chapter 20
Chapter 21
Chapter 22
Chapter 23
Appendix B.  Reference Tables
Python Keywords
Python Standard Operators and Functions
Numeric Type Operators and Functions
Sequence Type Operators and Functions
String Format Operator Conversion Symbols
String Format Operator Directives
String Type Built-in Methods
List Type Built-in Methods
Dictionary Type Built-in Methods
Set Types Operators and Functions
File Object Methods and Data Attriobutes
Python Exceptions
Special Methods for Classes
Python Operator Summary
Appendix 3.  About the Author
Index
SYMBOL
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