Enables students to confirm that programs run as expected. Students can also manipulate the code from the book's Companion Website (www.prenhall.com/deitel) and the authors' website (www.deitel.com).
Provides hundreds of valuable programming tips and facilitates learning.
Students can apply what they've learned in each chapter.
Illustrates the more complex real-world examples.
Helps students better understand the book's hundreds of programs.
Includes source code, hyperlinks to valuable Python demos and resources, and additional Python development tools, visit www.prenhall.com or www.deitel.com.
Discusses the methods that the World Wide Web Consortium provides in its Web Accessibility Initiative for making a Web site accessible to people with disabilities.
Provides extra hands-on experience and study aids for a minimal additional cost. Includes many hours of detailed, expert audio walkthroughs of the book's hundreds of live-code examples; post-assessment exams with hundreds of short-answer questions (all with answers), hundreds of self-review exercises drawn from the text all with answers), hundreds of programming exercises from the main text (these exercises don't have answers in the main text, but half of these exercises have answers in the Complete Training Course); hundreds of tips that are marked with icons and show how to write Python code that's portable, reusable, and optimized for performance; and full-text searching and hyperlinking.
Each How to Program text can be ordered as a Complete Training Course package, containing the main text and the corresponding Cyber Classroom—an interactive, multimedia, tutorial version of the book. The Complete Training Courses are a great value, giving students extra hands-on experience and study aids for a minimal additional cost.
Each Complete Training Course is compatible with Windows 95, Windows 98, Windows NT and Windows 2000 and includes the following features:
Practice exams that offer students hundreds of short-answer test questions and answers.
Hundreds of self-review questions that are drawn from the text, all with answers.
Hundreds of programming exercises that are drawn from the text, half with answers (the main text does not provide any answers to these exercises).
We offer the Complete Training Courses in a Web-based format. When professors order the Web-based version of a Complete Training Course, their students receive the corresponding How to Program book packaged with a URL and password that gives them six months of access to the Cyber Classroom software via the Web.
The authoritative DEITEL™ LIVE-CODE™ introduction to Python programming
This new book by the world's leading programming language textbook authors carefully explains how to use Python as a general-purpose programming language and how to program multi-tier, client/server, database-intensive, Internet- and Web-based applications.
Dr. Harvey M. Deitel and Paul J. Deitel are the founders of Deitel & Associates, Inc., the internationally-recognized corporate-training and content-creation organization specializing in Python, Visual Basic® .NET, C#, Visual C++® .NET, Java™, C++, C, XML, Perl, Internet, Web, wireless and object technologies. The Deitels are the authors of several worldwide #1 programming-language textbooks, including Java How to Program, 4/e, C++ How to Program, 3/e and Internet & World Wide Web How to Program, 2/e.
In Python How to Program, the Deitels and their colleagues, Jonathan Liperi and Ben Wiedermann, discuss topics you need to build complete Web-based applications, including:
Python How to Program includes extensive pedagogic features:
Python How to Program is the centerpiece of a complete family of resources for teaching and learning Python, including Web sites (www.deitel.com, www.prenhall.com/deitel and www.InformIT.com/deitel) with the book's source-code examples and other information for faculty, students and professionals;(Python Multimedia Cyber Classroom) containing hyperlinks, solutions to half the book's exercises and audio walkthroughs of the book's code examples; and e-mail access to the authors at deitel@deitel
For information on worldwide Deitel on-site seminars and to subscribe to the Deitel Buzz e-mail newsletter, visit: www.deitel.com
For information on current and forthcoming Deitel/Prentice Hall publications including How to Program Series books, Multimedia Cyber Classrooms Complete Training Courses (which include DEITEL™ books and Cyber Classrooms) and Web-Based Training Courses please see the last few pages of this book.
(NOTE: Each chapter begins with an Introduction.)
1. Introduction to Computers, Internet and World Wide Web.
What Is a Computer? Computer Organization. Evolution of Operating Systems. Personal Computing, Distributed Computing and Client/Server Computing. Machine Languages, Assembly Languages and High-Level Languages. Structured Programming. Object-Oriented Programming. Hardware Trends. History of the Internet and World Wide Web. World Wide Web Consortium (W3C). Extensible Markup Language (XML). Open-Source Software Revolution. History of Python. Python Modules. General Notes about Python and This Book. Tour of the Book. Internet and World Wide Web Resources.
First Program in Python: Printing a Line of Text. Modifying our First Python Program. Another Python Program: Adding Integers. Memory Concepts. Arithmetic. String Formatting. Decision Making: Equality and Relational Operators. Indentation. Thinking About Objects: Introduction to Object Technology.
Algorithms. Pseudocode. Control Structures. if Selection Structure. if/else and if/elif/else Selection Structures. while Repetition Structure. Formulating Algorithms: Case Study 1: (Counter-Controlled Repetition). Formulating Algorithms with Top-Down, Stepwise Refinement: Case Study 2: (Sentinel-Controlled Repetition). Formulating Algorithms with Top-Down, Stepwise Refinement: Case Study 3: (Nested Control Structures). Augmented Assignment Symbols. Essentials of Counter-Controlled Repetition. for Repetition Structure. Using the for Repetition Structure. break and continue Statements. Logical Operators. Structured-Programming Summary.
Program Components in Python. Functions. Module math Functions. Function Definitions. Random-Number Generation. Example: A Game of Chance. Scope Rules. Keyword import and Namespaces. Recursion. Example Using Recursion: The Fibonacci Series. Recursion vs Iteration. Default Arguments. Keyword Arguments.
Sequences. Creating Sequences. Using Lists and Tuples. Dictionaries. List and Dictionary Methods. References and Reference Parameters. Passing Lists to Functions. Sorting and Searching Lists. Multiple-Subscripted Sequences.
Client and Web Server Interaction. Simple CGI Script. Sending Input to a CGI Script. Using XHTML Forms to Send Input and Using Module cgi to Retrieve Form Data. Using cgi FieldStorage to Read Input. Other HTTP Headers. Example: Interactive Portal. Internet and World Wide Web Resources.
Implementing a Time Abstract Data Type with a Class. Special Attributes. Controlling Access to Attributes. Using Default Arguments with Constructors. Destructors. Class Attributes. Composition: Object References as Members of Classes. Data Abstraction and Information Hiding. Software Reusability.
Customizing String Representation: Method__str__ Customizing Attribute Access. Operator Overloading. Restrictions on Operator Overloading. Overloading Unary Operators. Overloading Binary Operators. Overloading Built-in Functions. Converting Between Types. Case Study: A Rational Class. Overloading Sequence Operations. Case Study: A SingleList Class. Overloading Mapping Operations. Case Study: A SimpleDictionary Class.
Inheritance: Base Classes and Derived Classes. Creating Base Classes and Derived Classes. Overriding Base-Class Methods in a Derived Class. Software Engineering with Inheritance. Composition vs Inheritance. “Uses A” and “Knows A” Relationships. Case Study: Point, Circle, Cylinder. Abstract Base Classes and Concrete Classes. Case Study: Inheriting Interface and Implementation. Polymorphism. Classes and Python 2.2.
Tkinter Overview ~. Simple Tkinter Example: Label Component. Event Handling Model. Entry Component. Button Component. Checkbutton and Radiobutton Components. Mouse Event Handling. Keyboard Event Handling. Layout Managers. Card Shuffling and Dealing Simulation. Internet and World Wide Web Resources.
Overview of Pmw. ScrolledListbox Component. ScrolledText Component. MenuBar Component. Popup Menus. Canvas Component. Scale Component. Other GUI Toolkits.
Raising an Exception. Exception-Handling Overview. Example: DivideByZeroError. Python Exception Hierarchy. finally Clause. Exception Objects and Tracebacks. Programmer-Defined Exception Classes.
Fundamentals of Characters and Strings. String Presentation. Searching Strings. Joining and Splitting Strings. Regular Expressions. Compiling Regular Expressions and Manipulating Regular-Expression Objects. Regular-Expression Repetition and Placement Characters. Classes and Special Sequences. Regular Expression String-Manipulation Functions. Grouping. Internet and World Wide Web Resources.
Data Hierarchy. Files and Streams. Creating a Sequential-Access File. Reading Data from a Sequential-Access File. Updating Sequential-Access Files. Random-Access Files. Simulating a Random-Access File: The shelve Module. Writing Data to a shelve File. Retrieving Data from a shelve File. Example: A Transaction-Processing Program. Object Serialization.
XML Documents. XML Namespaces. Document Object Model (DOM). Simple API for XML (SAX). Document Type Definitions (DTDs), Schemas and Validation. XML Vocabularies. Extensible Stylesheet Language (XSL). Internet and World Wide Web Resources.
Generating XML Content Dynamically. XML Processing Packages. Document Object Model (DOM). Parsing XML with xml.sax. Case Study: Message Forums with Python and XML. Internet and World Wide Web Resources.
Relational Database Model. Relational Database Overview: Books Database. Structured Query Language (SQL). Python DB-API Specification. Database Query Example. Querying the Books Database. Reading, Inserting and Updating a Database. Internet and World Wide Web Resources.
os.fork Function. os.system Function and os.exec Family of Functions. Controlling Process Input and Output. Interprocess Communication. Signal Handling. Sending Signals.
Thread States: Life Cycle of a Thread. threading. ThreadExample. Thread Synchronization. Producer/Consumer Relationship without Thread Synchronization. Producer/Consumer Relationship with Thread Synchronization. Producer/Consumer Relationship: Module Queue. Producer/Consumer Relationship: The Circular Buffer. Semaphores. Events.
Accessing URLs over HTTP. Establishing a Simple Server (Using Stream Sockets). Establishing a Simple Client (Using Stream Sockets). Client/Server Interaction with Stream Socket Connections. Connectionless Client/Server Interaction with Datagrams. Client/Server Tic-Tac-Toe Using a Multithreaded Server.
Ancient Ciphers to Modern Cryptosystems. Secret-Key Cryptography. Public-Key Cryptography. Cryptanalysis. Key-Agreement Protocols. Key Management. Digital Signatures. Public-Key Infrastructure, Certificates and Certificate Authorities. Security Protocols. Authentication. Security Attacks. Running Restricted Python Code. Network Security. Steganography. Internet and World Wide Web Resources.
Self-Referential Classes. Linked Lists. Stacks. Queues. Trees.
HTTP Sessions and Session-Tracking Technologies. Tracking Sessions in the Bookstore. Bookstore Architecture. Configuring the Bookstore. Entering the Bookstore. Obtaining the Book List from the Database. Viewing a Book's Details. Adding an Item to the Shopping Cart. Viewing the Shopping Cart. Checking Out. Processing the Order. Error Handling. Handling Wireless Clients (XHTML Basic and WML). Internet and World Wide Web Resources.
Introduction to PyOpenGL. PyOpenGL Examples. Introduction to Alice. Fox, Chicken and Seed Problem. Introduction to pygame. Python CD Player. Python Movie Player. Pygame Space Cruiser. Internet and World Wide Web Resources.
Python Servlets. Python Server Pages Overview. First Python Server Page Example. Implicit Objects. Scripting. Standard Actions. Directives. Case Study: Message Forums with Python and XML. Internet and World Wide Web Resources.
Introduction. Abbreviating Binary Numbers as Octal Numbers and Hexadecimal Numbers. Converting Octal Numbers and Hexadecimal Numbers to Binary Numbers. Converting from Binary, Octal or Hexadecimal to Decimal. Converting from Decimal to Binary, Octal or Hexadecimal. Negative Binary Numbers: Two's Complement Notation.
Introduction. Integrated Development Environment: IDLE. Other Integrated Development Environments. Internet and World Wide Web Resources.
Introduction. Resources for the Job Seeker. Online Opportunities for Employers. Recruiting Services. Career Sites. Internet and World Wide Web Resources.
Introduction. Unicode. Characters and Glyphs. Advantages and Disadvantages of Unicode. Unicode Consortium's Web Site. Using Unicode. Character Ranges.
Introduction. Markup Languages. Editing HTML. Common Elements. Headers. Linking. Images. Special Characters and More Line Breaks. Unordered Lists. Nested and Ordered Lists. Internet and World Wide Web Resources.
Introduction. Basic HTML Tables. Intermediate HTML Tables and Formatting. Basic HTML Forms. More Complex HTML Forms. Internal Linking. Creating and Using Image Maps. meta Elements. frameset Element. Nested framesets. Internet and World Wide Web Resources.
Introduction. Editing XHTML. First XHTML Example. W3C XHTML Validation Service. Headers. Linking. Images. Special Characters and More Line Breaks. Unordered Lists. Nested and Ordered Lists. Internet and World Wide Web Resources.
Introduction. Basic XHTML Tables. Intermediate XHTML Tables and Formatting. Basic XHTML Forms. More Complex XHTML Forms. Internal Linking. Creating and Using Image Maps. meta Elements. framese Element. Nested framesets. Internet and World Wide Web Resources.
Introduction. Inline Styles. Embedded Style Sheets. Conflicting Styles. Linking External Style Sheets. W3C CSS Validation Service. Positioning Elements. Backgrounds. Element Dimensions. Text Flow and the Box Model. User Style Sheets. Internet and World Wide Web Resources.
Introduction. Web Accessibility. Web Accessibility Initiative. Providing Alternatives for Images. Maximizing Readability by Focusing on Structure. Accessibility in XHTML Tables. Accessibility in XHTML Frames. Accessibility in XML. Using Voice Synthesis and Recognition with VoiceXML™. Cal1XML™. JAWS® for Windows. Other Accessibility Tools. Accessibility in Microsoft® Windows® 2000. Internet and World Wide Web Resources.
Introduction. Iterators. Generators. Nested Scopes. Internet and World Wide Web Resources.
Live in fragments no longer. Only connect.
Edward Morgan Forster
Welcome to the world of Python programming! Python is a powerful general-purpose programming language that is extremely effective for developing Internet and Web-based, database intensive, multi-tier, client/server systems. This book presents a great variety of leading edge computing technologies, and is our second book on open-source programming languages.
As we write these words, Python 2.2 has just been released, almost to the minute! We have worked hard to incorporate the 2.2 functionality throughout the book. Appendix O presents a few additional 2.2 features.
We hope you will find Python How to Program educational, entertaining and challenging. It was a joy to work on this project. The team at Deitel & Associates develops programming language textbooks and e-Learning materials. We work in almost every major programming language. We noticed something special while working on this book. Our developers and writers commented on how much they like Python. They appreciate its power, its readability and its conciseness. They like its pizzazz. They like the world of open-source software development that is generating an ever-growing base of modules.
Whether you are an instructor, a student, an experienced professional programmer or a novice, this book has much to offer you. Python is an excellent first programming language and is an equally excellent language for developing industrial-strength, commercial applications. For the student and the novice programmer, the early chapters of the book establish a solid foundation in the basics of programming. We discuss many programming models including structured programming, object-based programming, object-oriented programming and event-driven programming. For the professional developer, we have employed the "heavy-duty" Python functionality to create substantial, fully implemented systems. The capstone is the case study on building an online bookstore in Chapter 23this occupies approximately 70 pages of the text.
The standard basic topics are all heredata types, operators, control structures, arithmetic, strings, decision making, algorithm development, functions, and random numbers and simulation.
The book features a solid treatment of data structures with an early introduction to Python's built-in structures-lists, tuples and dictionaries-and a later rigorous treatment of traditional data structures including queues, stacks, linked lists and binary trees.
The book emphasizes Internet and Web developmentwe feature an early introduction to CGI then use it in several chapters to build Web-based applications. We include a full-chapter treatment of PSP (Python Server Pages) where we re-engineer the message forum case study presented in Chapter 16.
The book features a detailed, three-chapter treatment of object-oriented programming covering classes, encapsulation, objects, attributes, methods, constructors, destructors, customization, operator overloading, inheritance, base classes, derived classes and polymorphism.
We include a thorough treatment of graphical user interface (GUI) programming, with Tkinter, using event-driven programming, labels, buttons, check buttons, radio buttons, mouse-event handling, keyboard-event handling, layout managers, and a whole range of advanced GUI capabilities for creating and manipulating menus and scrolling components.
We discuss exception handling for making programs more robust. We present a substantial treatment of Python's powerful string-manipulation capabilities and we tackle head-on the difficultyet enormously powerfultopic of regular expressions.
We discuss file processing, sequential access files, random-access files (and the shelve module). We develop a transaction-processing program and consider object serialization. The discussions of file processing provide a nice lead-in to our treatment of database programming with Python's Database Application Programming Interface (DB-API). We discuss the relational database model and present an introduction to SQL (Structured Query Language).
Many people are familiar with HTML; yet few know that the World Wide Web Consortiumcreator of HTML technologyhas declared HTML to be a legacy technology that will undergo no further development. Nevertheless, HTML is still important, so we have provided two appendices on it. The world is evolving towards XML (eXtensible Markup Language). In the interim, contemporary Web development is using a transition technology called XHTML. We present two appendices on this important subject and use XHTML in various applications throughout the book. We present a chapter-length general introduction to XML, an absolute must subject for today's Web applications developers. We then include a full-chapter treatment of Python-specific XML processing and include a detailed case study in which we use CGI and XML to build message forums.
Computer applications have generally been good at doing one thing at a time; today's more sophisticated applications need to be able to do many things in parallel, or as we prefer to say in the computer fieldconcurrently. We provide full chapters on process management and multithreading. These technologies give the Python applications programmer capabilities that used to be available only to systems programmers working down at the operating systems level.
We discuss networking, including the HTTP protocol of the Web, client/server networking with stream sockets, connectionless client/server interaction using datagrams, and we implement a client/server tic-tac-toe game using a multithreaded server.
We present a thorough general discussion of computer security, then deal with some Python-specific security issues. We discuss executing potentially harmful code in a restricted environment using module Bastion. We demonstrate encrypting text with module rotor.
As a capstone exercise for the book, in Chapter 23 we present a detailed case study that implements online bookstore e-business using a great many technologies discussed in the earlier chapters and the appendices. We introduce HTTP sessions and session tracking and build our bookstore as a mufti-tier, client/server system able to handle a variety of clients, including a standard Web browser (using XHTML) and wireless clients (using WML and XHTML Basic).
We present a full chapter on multimedia, including an introduction to PyOpenGL with 3-D graphics examples and an introduction to Alice, a 3D environment that provides objects which can be animated with Python scripts. We demonstrate pygame by designing a CD player, a movie player and a space-cruiser game.
Recognizing the importance of server-side development, we introduce PSP (Python Server Pages) as an alternative to CGI, and we convert the message forum case study from CGI technology to PSP.
The book is loaded with valuable appendices, including the Operator Precedence Chart, ASCII Character Set, Number Systems (binary, octal, decimal, hexadecimal), Python Development Environments, HTML, XHTML, CSS (Cascading Style Sheets), Career Opportunities (with lots of Web resources) and Unicode. We include an appendix on Accessibility (which overviews issues affecting, and resources for, people with disabilities). We close with an appendix on Additional Python 2.2 Features, including discussions on iterators, generators and nested scopes.
As you read this book, if you have an questions, just send an e-mail to email@example.com. We will respond promptly. Please visit with us from time to time at www.deitel.com and be sure to sign up there for The DEITEL BUZZ e-mail newsletter. We use the Web site and the newsletter to keep our readers up to the minute on Python and our products and services.
This text contains many additional features, including:
This text provides many other topics in addition to the features previously listed. For a complete list of each chapter's features, visit page 15 of Chapter 1, Tour of the Book.
This text went to publication at the same time that the final version of Python 2.2 was released. However, all the code examples in this book were tested in Python 2.2b2 (Python Version 2.2 Beta 2) and with Release Candidate 1, on both the Windows and Linux operating systems, and the text demonstrates 2.2 features and functionality in every applicable chapter. This section overviews the 2.2 capabilities presented in Python How to Program.
Floor Division and True Division. Python 2.2 introduces a new operator (//) for "floor" (integer) division. In the current and previous versions of Python, the default behavior of the / division operator is floor division; in future versions, the default behavior will be "true" (floating-point) division. By defining two division operators, the new versions of Python eliminates the type ambiguity that results in programs that use both integer and floating-point values for division. Section 2.6 discusses the difference between floor division and true division and explains how a program can change the default behavior of the / operator to perform true division.
Nested Scopes. Python 2.2 introduces nested scopes, which means that nested classes, methods and functions now have access to variables defined in their enclosing scope. This behavior is particularly helpful for writing lambda lambda expressions. Chapter 4 discusses Python's basic scoping rules and provides a footnote that contains a Web resource for further information on nested scopes. The nested scoping behavior is most important to programmers who use Python in a functional-programming idiom. We also discuss nested scopes in Appendix O, Additional Python features. As this book focuses mainly on the object-oriented style of programming, we provide only a high-level motivation for nested scopes and suggest further resources where the reader can learn more about nested scopes and functional programming in Python.
More Object-Oriented Functionality. Most of the new features in Python 2.2 add more object-oriented functionality to the language. Chapters 8 and 9 introduce several of these new features. In Chapter 8, we discuss the methods that a programmer-defined class can overload to define behavior for operators, including the new // operator. We also introduce a dictionary method, new to 2.2, that enables programs to use if/in statements to test whether a dictionary contains a particular key. In Chapter 9, we discuss the most anticipated new featurethe ability for programmer-defined classes to inherit from built-in types. We present a substantial example that inherits from built-in type list to implement a programmer-defined list that contains only unique elements. We also discuss other new object-oriented features, including static methods,__ slots__ (for defining the attributes an object of a class may contain), method__getattribute__(that executes each time a client accesses an object's attribute) and properties (that allow classes to define get/set methods that execute when a client accesses an attribute).
Iterators. Appendix O contains additional 2.2 features that are not covered in the main text. We begin with a thorough treatment of iteratorsspecial objects for progressing through the values of a sequence. Section 0.2 contains two examples that present programmer-defined iterator classes and demonstrate a client of the class using an iterator to obtain values from a sequence. The first example illustrates how to define a class whose objects support iterators; the second example presents a computer guessing game that shows how iterators can be used to process sequences of indeterminate size. The new iterator mechanism in Python 2.2 enables the language to provide a significant performance enhancement over previous versions and improves software design by allowing programmers to separate iteration behavior from random-access behavior.
Generators. Generators also provide new performance and design benefits. A generator is a "resumable function" that remembers its state between invocations. Often, a program writes a generator to define how to produce elements of a sequence in a simple, straightforward manner. Generators also are useful for performing recursive tasks or tasks that would require complex logic and state information to implement with "traditional" functions. Section 0.2 discusses generators in the context of these issues and defines two versions of a generator that computes the Fibonacci sequence. The first version produces the next value in the sequence indefinitely; the second produces all the sequence values up through and including a user-defined nth value.
Students Enjoy Learning a Leading-Edge Language
Students are highly motivated by the fact that they are learning a leading-edge language, Python, and a leading-edge programming paradigm (object-oriented programming) that will be immediately useful to them as they enter the business world. This increases their enthusiasm for the materialwhich is essential when you consider that there is much more to learn in a Python course now that students must master both the base language and substantial modules as well.
A World of Object Orientation
In the late 1990s, universities were still emphasizing procedural programming. The leading-edge courses were using object-oriented C++, but these courses generally mixed a substantial amount of procedural programming with object-oriented programmingsomething that C++ lets programmers do. Many instructors now are emphasizing a pure object-oriented programming approach. This book takes a predominantly object-oriented approach because of the object orientation provided in Python.
Focus of the Book
Our goal was clear: Produce a Python textbook for introductory-level university courses in computer programming aimed at students with little or no programming experience, yet offer the depth and the rigorous treatment of theory and practice demanded by both professionals and students in traditional, upper-level programming courses. To meet these objectives, we produced a comprehensive book that patiently teaches the principles of computer programming and of the Python language, including control structures, object-oriented programming, Python modules, graphical-user-interface concepts, event-driven programming and more. After mastering the material in this book, students will be well-prepared to program "industrial-strength" applications in Python.
People want to communicate. Sure, they have been communicating since the dawn of civilization, but the potential for information exchange has increased dramatically with the evolution of various technologies. Until recently, even computer communications were limited mostly to digits, alphabetic characters and special characters. The current wave of communication technology involves the distribution of multimediapeople enjoy using applications that transmit color pictures, animations, voices, audio clips and even full-motion color video over the Internet. At some point, we will insist on three-dimensional, moving-image transmission.
There have been predictions that the Internet will eventually replace radio and television as we know them today. Similarly, it is not hard to imagine newspapers, magazines and books delivered to "the palm of your hand" (or even to special eyeglasses) via wireless communications. Many newspapers and magazines already offer Web-based versions, and some of these services have spread to the wireless world. When cell phones were first introduced, they were large and cumbersome. Today, they are small devices that fit in our pockets, and many are Internet-enabled. Wireless technology already enables streaming-video and graphics-intensive services, such as video conference calls and multi-player video games. Chapter 23, Case Study: Online Bookstore and Chapter 24, Multimedia demonstrate the possibilities of wireless Internet and multimedia applications.
Python How to Program contains a rich collection of examples, exercises and projects drawn from many fields and designed to provide students with a chance to solve interesting, real-world problems. The code examples in this text have been tested on Windows 2000 and Linux. The book concentrates on the principles of good software engineering, and stresses program clarity. We are educators who teach edge-of-the-practice topics in industry classrooms worldwide. We avoid arcane terminology and syntax specifications in favor of teaching by example. The text emphasizes good pedagogy.
LIVE-CODE Teaching Approach
Python How to Program is loaded with numerous examples. This style exemplifies the way we teach and write about programming and is the focus of our multimedia Cyber Classrooms and Web-based training courses. Each new concept is presented in the context of a complete, working example that is immediately followed by one or more windows showing the program's input/output dialog or graphical display. We call this method of teaching and writing the LIVE-CODE Approach. We use programming languages to teach programming languages. Reading the examples in the text is much like entering and running them on a computer.
World Wide Web Access
All of the examples for Python How to Program (and our other publications) are available on the Internet free for download from the following Web sites:
Registration is quick and easy. We suggest downloading all the examples, then running each program as you read the corresponding text. Make changes to the examples and immediately see the effects of those changesthis is a great way to learn programming. We also provide instructions for installing various software used in this book (e.g., Apache Software Foundation's Apache Web Server). Additional setup instructions for other Web servers and software can be found at our Web sites with the examples. Note: This is copyrighted material. Feel free to use it as you study, but you may not republish any portion of it in any form without explicit permission from Prentice Hall and the authors.
Each chapter begins with objectives that inform students of what to expect and give them an opportunity, after reading the chapter, to determine whether they have met the intended goals. The objectives serve as confidence builders and as a source of positive reinforcement.
The chapter objectives are followed by sets of quotations. Some are humorous, some are philosophical and some offer interesting insights. We have found that students enjoy relating the quotations to the chapter material. Many of the quotations are worth a "second look" after you read each chapter.
The chapter outline enables students to approach the material in top-down fashion. Along with the chapter objectives, the outline helps students anticipate future topics and set a comfortable and effective learning pace.
Approximately 14,930 Lines of Code in 281 Example Programs (with Program Outputs)
We present Python features in the context of complete, working Python programs. The programs range in size from just a few lines of code to substantial examples containing several hundred lines of code. All examples are available on the book's CD or free for download at www.deitel.com.
An abundance of charts, line drawings and program outputs is included. The discussion of control structures, for example, features carefully drawn flowcharts. Note: We do not teach flowcharting as a program-development tool, but we do use a brief, flowchart-oriented presentation to explain the precise operation of each Python control structure.
412 Programming Tips
We have included programming tips to help students focus on important aspects of program development. We highlight hundreds of these tips in the form of Good Programming Practices, Common Programming Errors, Testing and Debugging Tips, Performance Tips, Portability Tips, Software Engineering Observations and Look-and-Feel Observations. These tips and practices represent the best the authors have gleaned from a combined seven decades of programming and teaching experience. One of our studentsa mathematics majortold us that she feels this approach is like the highlighting of axioms, theorems and corollaries in mathematics books; it provides a foundation on which to build good software.
Summary (1462 Summary bullets)
Each chapter ends with additional pedagogical devices. We present a thorough, bullet-list-style summary of the chapter. On average, there are 43 summary bullets per chapter. This helps the students review and reinforce key concepts.
Terminology (2485 Terms)
We include an alphabetized list of the important terms defined in the chapter in a Terminology section. Again, this serves as further reinforcement. On average, there are 73 terms per chapter. Each term also appears in the index, so the student can locate terms and definitions quickly.
615 Self-Review Exercises and Answers (Count Includes Separate Parts)
Extensive self-review exercises and answers are included for self-study. These questions and answers give the student a chance to build confidence with the material and prepare for the regular exercises. Students should be encouraged to attempt all the self-review exercises and check their answers.
370 Exercises (Solutions in Instructor's Manual; Count Includes Separate Parts)
Each chapter concludes with a substantial set of exercises that involve simple recall of important terminology and concepts; writing individual Python statements; writing small portions of Python methods and classes; writing complete Python methods, classes and applications; and writing major projects. These exercises cover a wide variety of topics, enabling instructors to tailor their courses to the unique needs of their audiences and to vary course assignments each semester. Instructors can use the exercises to form homework assignments, short quizzes and major examinations. The solutions for the exercises are included in the Instructor's Manual and on the disks available only to instructors through their Prentice-Hall representatives. NOTE: Please do not write to us requesting the instructor's manual. Distribution of this publication is strictly limited to college professors teaching from the book. Instructors may obtain the solutions manual from their regular Prentice Hall representatives. We regret that we cannot provide the solutions to professionals. Solutions to approximately half the exercises are included on the Python Multimedia Cyber Classroom CD-ROM (available in April 2002 at www.InformIT.com/cyberclassrooms; also see the last few pages of this book or visit www.deitel.com for ordering instructions). Also available in April 2002 is the boxed product, The Complete Python Training Course, which includes both our textbook, Python How to Program and the Python Multimedia Cyber Classroom. All of our Complete Training Course products are available at bookstores and online booksellers, including www.InformIT.com.
Approximately 4212 Index Entries (with approximately 5733 Page References)
We have included an extensive Index at the back of the book. Using this resource, students can search for any term or concept by keyword. The Index is especially useful to practicing programmers who use the book as a reference. Each of the 2485 terms in the Terminology sections appears in the Index (along with many more index items from each chapter). Students can use the Index in conjunction with the Terminology sections to ensure that they have covered the key material in each chapter.
"Double Indexing" of All Python LIVE-CODE Examples
Python How to Program has 281 LIVE-CODE examples, which we have "double indexed." For every Python source-code program in the book, we took the file name with the .py extension, such as Book.py, and indexed it both alphabetically (in this case, under "B") and as a subindex item under "Examples." This makes it easier to find examples that are demonstrating particular features.
There are a number of Python products available for download from the Internet. We wrote Python How to Program using the Python Core Language 2.2 final release, and other software we have included on the CD-ROM that accompanies this text. This software includes the Apache Web Server 1.3.22, from the Apache Software Foundation and Alice99, a multimedia application for creating 2D and 3D graphics. The CD-ROM includes the wireless browser, Pixo 2.1, the IBM WebSphere Voice Server 1.5, a text-to-speech engine and Web-ware 0.6 for Python, which contains PSP software components for developing Web-based server-side applications. As we mentioned earlier, Python 2.2 was released almost to the minute that we released Python How to Program to Prentice Hall for publication. Some of the Python software packages you many want to use may not yet work with Python 2.2. If that is the case, please try running those software packages on Python 2.1, which you can download from www.python.org. If you still experience problems, please check the Python FAQs at www.deitel.com. The CD-ROM contains Windows and Linux versions of the software, where possible.
Python How to Program has extensive ancillary materials for instructors teaching from the book. The Instructor's CD contains the Instructor's Manual with solutions to the vast majority of the end-of-chapter exercises and a Test Item File of multiple-choice questions (approximately two per book section). In addition, we provide PowerPoint® slides containing all the code and figures in the text. You are free to customize these slides to meet your own classroom needs. Prentice Hall provides a Companion Web Site (www.prenhall.com/deitel) that includes resources for instructors and students. For instructors, the Web site has a Syllabus Manager for course planning, links to the PowerPoint slides and reference materials from the appendices of the book (such as operator precedence chart, character set and Web resources). For students, the Web site provides chapter objectives, additional selfreview exercises and answers, chapter highlights and reference materials.
We have prepared an interactive, multimedia, CD-ROM-based, software version of Python How to Program, called the Python Multimedia Cyber Classroom. This resource is loaded with e-learning features that are ideal for both education and reference. The Cyber Classroom is packaged with the textbook at a discount in The Complete Python Training Course. If you already have the book and would like to purchase the Python Multimedia Cyber Classroom separately, please visit www.InformIT.com/cyberclassrooms. The ISBN number for the CD-ROM format of the Python Multimedia Cyber Classroom is 0-13-067376-5 and the Web-based training format is ISBN number 0-13-067381-1. Many Deitel Cyber Classrooms are available in CD-ROM and Web-based formats.
The CD provides an introduction in which the authors overview the Cyber Classroom's features. The textbook's 281 LIVE-CODE example Python programs truly "come alive" in the Cyber Classroom. If you are viewing a program and want to execute it, you simply click the lightning-bolt icon, and the program will run. You immediately will seeand hear, when working with audio-based multimedia programsthe program's outputs. If you want to modify a program and see the effects of your changes, simply click the floppy-disk icon that causes the source code to be "lifted off' the CD and "dropped into" one of your own directories so you can edit the text, recompile the program and try out your new version. Click the audio icon, and one of the authors will discuss the program and "walk you through" the code.
The Cyber Classroom also provides navigational aids, including extensive hyperlinking. The Cyber Classroom is browser based, so it remembers sections that you have visited recently and allows you to move forward or backward among these sections. The thousands of index entries are hyperlinked to their text occurrences. Furthermore, when you enter a term using the "find" feature, the Cyber Classroom will locate occurrences of that term throughout the text. The Table of Contents entries are "hot," so clicking a chapter name takes you immediately to that chapter.
Students like the fact that solutions to approximately half the exercises in the book are included with the Cyber Classroom. Studying and running these extra programs is a great way for students to enhance their learning experience.
Students and professional users of our Cyber Classrooms tell us that they like the interactivity and that the Cyber Classroom is an effective reference due to its extensive hyperlinking and other navigational features. We received an email from a person who said that he lives "in the boonies" and cannot take a live course at a university, so the Cyber Classroom provided an ideal solution to his educational needs.
Professors tell us that their students enjoy using the Cyber Classroom and spend more time on the courses and master more of the material than in textbook-only courses. For a complete list of the available and forthcoming Cyber Classrooms and Complete Training Courses, see the Deitel Series page at the beginning of this book, the product listing and ordering information at the end of this book or visit www.deitel.com, www.prenhall.com/deitel and www.InformIT.com/deitel.
e-Books and Support for Wireless Devices
Wireless devices will play an enormous role in the future of the Internet. Given recent bandwidth enhancements and the emergence of 2.5 and 3G technologies, it is projected that, within two years, more people will access the Internet through wireless devices than through desktop computers. Deitel & Associates, Inc., is committed to wireless accessibility and has recently published Wireless Internet & Mobile Business How to Program. To fulfill the needs of a wide range of customers, we are developing our content both in traditional print formats and in newly developed electronic formats, such as e-books so that students and professors can access content virtually anytime, anywhere. Visit www.deitel.com for periodic updates on these initiatives.
Deitel & Associates, Inc., is partnering with Prentice Hall's parent company, Pearson PLC, and its information technology Web site, www.InformIT.com, to launch the Deitel e-Matter series at www.InformIT.com/deitel. This series will provide professors, students and professionals with an additional source of information on specific programming topics. e-Matter consists of stand-alone sections taken from published texts, forthcoming texts or pieces written during the Deitel research-and-development process. Developing e-Matter based on pre-publication books allows us to offer significant amounts of the material to early adopters for use in courses. Some possible Python e-Matter titles we are considering include Object-Oriented Programming in Python; Graphical User Interface Programming in Python and Multithreading in Python.
Course Management Systems: WebCT, Blackboard, and CourseCompass
We are working with Prentice Hall to integrate our How to Program Series courseware into three Course Management Systems: WebCT, Blackboard and CourseCompass. These Course Management Systems enable instructors to create, manage and use sophisticated Webbased educational programs. Course Management System features include course customization (such as posting contact information, policies, syllabi, announcements, assignments, grades, performance evaluations and progress tracking), class and student management tools, a gradebook, reporting tools, communication tools (such as chat rooms), a whiteboard, document sharing, bulletin boards and more. Instructors can use these products to communicate with their students, create online quizzes and tests from questions directly linked to the text and automatically grade and track test results. For more information about these upcoming products, visit www.deitel.com/whatsnew.html. For demonstrations of existing WebCT, Blackboard and CourseCompass courses, visit cms.prenhall.com/webct/index.html, cms.prenhall.com/blackboard/index.html and cms.prenhall.com/coursecompass/index.html, respectively.
Deitel Column in the InformIT Newsletters
Deitel & Associates, Inc., contributes a weekly column to the popular InformIT newsletter, currently subscribed to by more than 800,000 IT professionals worldwide. For opt-in registration, visit www.InformIT.com.
Our own free, opt-in newsletter includes commentary on industry trends and developments, links to articles and resources from our published books and upcoming publications, information on future publications, product-release schedules, programming tips, errata, additional insights and more. For opt-in registration, visit www.deitel.com.