Learning Python is an introduction to the increasingly popular Python programming language. Python is an interpreted, interactive, object-oriented scripting language. Python is growing in popularity because:

It is available on all important platforms: Windows NT, Windows 95, Windows 98, Linux, all major UNIX platforms, MacOS, and even the BeOS.

It is open-source software, copyrighted but freely available for use, even in commercial applications.

Its clean object-oriented interface makes it a valuable prototyping tool for C++ programmers.

It works well with all popular windowing toolkits, including MFC, Tk, Mac, X11, and Motif.Learning Python is written by Mark Lutz, author ofProgramming Python and Python Pocket Reference; and David Ascher, a vision scientist and Python user.This book starts with a thorough introduction to the elements of Python: types, operators, statements, classes, functions, modules, and exceptions. By reading the first part of the book, the reader will be able to understand and construct programs in the Python language. In the second part of the book, the authors present more advanced information, demonstrating how Python performs common tasks and presenting real applications and the libraries available for those applications.All the examples use the Python interpreter, so the reader can type them in and get instant feedback. Each chapter ends with a series of exercises. Solutions to the exercises are in an appendix.

The Core Language

Chapter 1 Getting Started

Why Python?

How to Run Python Programs

A First Look at Module Files

Python Configuration Details

Summary

Exercises

Chapter 2 Types and Operators

Python Program Structure

Why Use Built-in Types?

Numbers

Strings

Lists

Dictionaries

Tuples

Files

General Object Properties

Built-in Type Gotchas

Summary

Exercises

Chapter 3 Basic Statements

Assignment

Expressions

Print

if Tests

while Loops

for Loops

Common Coding Gotchas

Summary

Exercises

Chapter 4 Functions

Why Use Functions?

Function Basics

Scope Rules in Functions

Argument Passing

Odds and Ends

Function Gotchas

Summary

Exercises

Chapter 5 Modules

Why Use Modules?

Module Basics

Module Files Are Namespaces

Import Model

Reloading Modules

Odds and Ends

Module Gotchas

Summary

Exercises

Chapter 6 Classes

Why Use Classes?

Class Basics

Using the Class Statement

Using Class Methods

Inheritance Searches Namespace Trees

Operator Overloading in Classes

Namespace Rules: The Whole Story

Designing with Classes

Odds and Ends

Class Gotchas

Summary

Exercises

Chapter 7 Exceptions

Why Use Exceptions?

Exception Basics

Exception Idioms

Exception Catching Modes

Odds and Ends

Exception Gotchas

Summary

Exercises

The Outer Layers

Chapter 8 Built-in Tools

Aside: The sys Module

Built-in Functions

Library Modules

Exercises

Chapter 9 Common Tasks in Python

Data Structure Manipulations

Manipulating Files

Manipulating Programs

Internet-Related Activities

Bigger Examples

Exercises

Chapter 10 Frameworks and Applications

An Automated Complaint System

Interfacing with COM: Cheap Public Relations

A Tkinter-Based GUI Editor for Managing Form Data

Design Considerations

JPython: The Felicitous Union of Python and Java

Other Frameworks and Applications

Exercises

Appendixes

Appendix Python Resources

The Python Language Web Site

Python Software

Python Documentation and Books

Newsgroups, Discussion Groups, and Email Help

Conferences

Support Companies, Consultants, Training

Tim Peters

Appendix Platform-Specific Topics

Unix

Windows-Specific Information

Macintosh-Specific Information

Java

Other Platforms

Appendix Solutions to Exercises

Chapter 1

Chapter 2

Chapter 3

Chapter 4

Chapter 5

Chapter 6

Chapter 7

Chapter 8

Chapter 9

Chapter 10

Colophon

Mark Lutz

Mark Lutz is an independent Python trainer, writer, and software developer, and is one of the primary figures in the Python community. He is the author of the O'Reilly books Programming Python and Python Pocket Reference (both in 2nd Editions), and co-author of Learning Python (both in 2nd Editions). Mark has been involved with Python since 1992, began teaching Python classes in 1997, and has instructed over 90 Python training sessions as of early 2003. In addition, he holds BS and MS degrees in computer science from the University of Wisconsin, and over the last two decades has worked on compilers, programming tools, scripting applications, and assorted client/server systems. Whenever Mark gets a break from spreading the Python word, he leads an ordinary, average life with his kids in Colorado. Mark can be reached by email at , or on the web at http://www.rmi.net/~lutz.

David Ascher

David Ascher is the lead for Python projects at ActiveState, including Komodo, ActiveState's integrated development environment written mostly in Python. David has taught courses about Python to corporations, in universities, and at conferences. He also organized the Python track at the 1999 and 2000 O'Reilly Open Source Conventions, and was the program chair for the 10th International Python Conference. In addition, he co-wrote Learning Python (both editions) and serves as a director of the Python Software Foundation. David holds a B.S. in physics and a Ph.D. in cognitive science, both from Brown University.

Our look is the result of reader comments, our own experimentation, and feedback from distribution channels. Distinctive covers complement our distinctive approach to technical topics, breathing personality and life into potentially dry subjects. The animal on the cover of Learning Python is a wood rat (Neotoma, family Muridae). The wood rat lives in a wide range of living conditions (mostly rocky, scrub, and desert areas) over much of North and Central America, generally at some distance from humans, though they occasionally damage some crops. They are good climbers, nesting in trees or bushes up to six meters off the ground; some species burrow underground or in rock crevices or inhabit other species' abandoned holes.These greyish-beige, medium-sized rodents are the original pack rats: they carry anything and everything into their homes, whether or not it's needed, and are especially attracted to shiny objects such as tin cans, glass, and silverware. Mary Anne Weeks Mayo was the production editor and copyeditor ofLearning Python; Sheryl Avruch was the production manager; Jane Ellin, Melanie Wang, and Clairemarie Fisher O'Leary provided quality control. Robert Romano created the illustrations using Adobe Photoshop 5 and Macromedia FreeHand 8. Mike Sierra provided FrameMaker technical support. Ruth Rautenberg wrote the index.Edie Freedman designed the cover of this book, using a 19th-century engraving from the Dover Pictorial Archive. The cover layout was produced with QuarkXPress 3.32 using the ITC Garamond font. Whenever possible, our books use RepKover(TM), a durable and flexible lay-flat binding. If the page count exceeds RepKover's limit, perfect binding is used.The inside layout was designed by Nancy Priest and implemented in FrameMaker 5.5 by Mike Sierra. The text and heading fonts are ITC Garamond Light and Garamond Book. This colophon was written by Nancy Kotary.

I think this book is a great start for everyone who wants to program (not only Python, because I think Python is among the best languages to start with). I've quite a good programming background and it didn't bore me at all although it doesn't require any programming skills. Go for it!

For me the book was definitely a 5-bigeyed-critters read. However, I've had some exposure to Unix in various forms, shell programming, lots of C, and another interpreter with introspective capability (Forth!). Plus a little recreational reading and programming in OOP but no real professional committment to it yet.

Given this background, the book really hit the spot for me. Most of the knowledge required to understand the subtler points was in place, making it interesting and gratifying to plow through.

However, my rating of 3-bigeyed-critters is to indicate that it is probably to ambitious for a newbie learner (as has also been pointed out in another review). Perhaps there should be a "training-wheels" Python Boot Camp book that will give the real neophyte a better feel for the poles of functional and procedural programming between which basic Python seems to oscillate. This is not a slam against Python (I wish I could write something as good on the job, let alone in my spare time), but a frank recognition of its origin as a work-in-progress that was and continues to be molded over time.

I've never had as much quick payback from a book and language as I have with this book. When I saw that email capabilities were provided, I looked up an smtplib example on the Web and commandeered it for a Monte Carlo computation of the value of pi. Basically, you generate random coordinates in a square, count them and also the fraction that fall inside the inscribed circle. By comparing the hits in the circle to the hits in the square, you can arrive at a value for pi without resorting to calculus. It's a brute force approach, and it's not fun having to sit and watch the results scroll by on the screen, so I used smtplib to send me an email every billion iterations (one for each random pair of coordinates generated) with the latest (gradually improving) value for pi. Nice! Long integer support really helped with this, too. But I've never had a program of my own send me mail before: definitely worth the price of the book.

I had heard that Python was a good prototyping language some time ago, but was actually about to settle in and grind out something in C and VB/VBScript when I realized that Python had been installed on my Windows XP Home Edition without my even knowing it. I found out it was there after enabling Explorer display of hidden files and directories. There it was, Python 2.2, so I tried it out, verified that it worked, and then decided to get a book or two and learn more about it. "Learning Python" is my first exposure, with occasional excursions into the "Python Cookbook". Although I ordered the VBScript books from O'Reilly before I went off on this Python tangent, they will probably lie around unmolested until I've seen just what I can do in Python. I'll probably read them later and do something with them for resume candy, but I expect that I'll probably reach for Python first even after I've done the VB thing.

Also very gratifying was the fact that in spite of only a little exposure to HTML and no knowledge at all of CGI, I was able to understand the HTML/CGI example which will feed into some browser-enabled projects I'm working on now. All in all, a great language and a great book to get started, if you've been around the block with computers and maybe a few other languages.

Thanks to the authors for this book, and thanks to O'Reilly for being there all these years with killer technical documentation. The publisher's reputation for excellence is why I reach for the books with the animals first. I wish there had been something doing this for the IBM 360 and its successors!

This book, while very useful, is not what it seems or what the title claims. While I am fairly well versed in programming concepts and really like Python, the novice would do well to ignore the book's Title and introductory Prerequisites section that claims no background in programming is necessary. Get another book first. There is an assumption throughout the text that the user knows what different programming concepts are and has a basic undestadning of program flow, methods, OOP, etc. and even vague C++ knowledge would be helpful. My favorite example that appears is 2**X, with no previous mention of what this means--You know what it means if you know what it means. Python is an excellent introductory language, but use another book.

I love O'Reilly books for their logical layout and comprehensive and concise nature. "Learning Python" didn't fit the mold or quality I expected.

Ok -- so I am C/C++ and Java programmer and this was my first attempt at learning a scripting language. This book wasnt for me -- I found the Tutorial by Guido van Rossum that ships with the Python Distribution much more useful. Maybe this book will serve as a good reference or a doorstop. Better still -- can I have my money back !

Once in a great while comes a programming book well-ordered enough for handy reference and pleasant enough to read while waiting in line. _Learning_Python_ is one of these. Although it would be easy to allow my enthusiasm for Python influence my opinion of the book, it is hardly necessary to do so. It compliments material found in the tutorial distributed with Python by building a foundation of basic knowledge needed to write good code and actually determine "where to go from here". It is appreciated.