Python How To Program

by 12:39 0 comments



For Python programming courses or Web programming courses focusing on Python programming found in departments of Computer Science, CIS, MIS, IT, Business, Engineering and Continuing Education.

An exciting addition to the How to Program series, Python How to Program provides a comprehensive introduction to this powerful object-oriented programming language, which has clear syntax and the ability to bring together several technologies quickly and easily. Python How to Program covers introductory programming techniques as well as more advanced topics such as graphical user interfaces, databases, wireless Internet programming, networking and multimedia. Students will learn principles that are applicable to both systems development and Web programming.

Table of Contents

(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.

2. Introduction to Python Programming.
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.

3. Control Structures.
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.

4. Functions.
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.

5. Lists, Tuples and Dictionaries.
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.

6. Introduction to the Common Gateway Interface (CGI).
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.

7. Object-Based Programming.
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.

8. Customizing Classes.
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.

9. Object-Oriented Programming: Inheritance.
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.

10. Graphical User Interface Components: Part 1.
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.

11. Graphical User Interface Components: Part 2.
Overview of Pmw. ScrolledListbox Component. ScrolledText Component. MenuBar Component. Popup Menus. Canvas Component. Scale Component. Other GUI Toolkits.

12. Exception Handling.
Raising an Exception. Exception-Handling Overview. Example: DivideByZeroError. Python Exception Hierarchy. finally Clause. Exception Objects and Tracebacks. Programmer-Defined Exception Classes.

13. String Manipulation and Regular Expressions.
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.

14. File Processing and Serialization.
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.

15. Extensible Markup Language (XML).
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.

16. Python XML Processing.
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.

17. Database Application Programming Interface(DB-API).
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.

18. Process Management.
os.fork Function. os.system Function and os.exec Family of Functions. Controlling Process Input and Output. Interprocess Communication. Signal Handling. Sending Signals.

19. Multithreading.
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.

20. Networking.
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.

21. Security.
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.

22. Data Structures.
Self-Referential Classes. Linked Lists. Stacks. Queues. Trees.

23. Case Study: Online Bookstore.
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.

24. Multimedia.
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.

25. Python Server Pages (PSP).
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.

Appendix A. Operator Precedence Chart.

Appendix B. ASCII Character Set.

Appendix C. Number Systems.
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.

Appendix D. Python Development Environments.
Introduction. Integrated Development Environment: IDLE. Other Integrated Development Environments. Internet and World Wide Web Resources.

Appendix E. Career Opportunities.
Introduction. Resources for the Job Seeker. Online Opportunities for Employers. Recruiting Services. Career Sites. Internet and World Wide Web Resources.

Appendix F. Unicode®.
Introduction. Unicode. Characters and Glyphs. Advantages and Disadvantages of Unicode. Unicode Consortium's Web Site. Using Unicode. Character Ranges.

Appendix G. Introduction to HyperText Markup Language 4: Part 1.
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.

Appendix H. Introduction to HyperText Markup Language 4: Part 2.
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.

Appendix I. Introduction to XHTML: Part 1.
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.

Appendix J. Introduction to XHTML: Part 2.
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.

Appendix K. Cascading Style Sheets™ (CSS).
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.

Appendix L. Accessibility.
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.

Appendix M. HTML/XHTML Special Characters.

Appendix N. HTML/XHTML Colors.

Appendix O. Additional Python 2.2 Features.
Introduction. Iterators. Generators. Nested Scopes. Internet and World Wide Web Resources.




Signature “Live-Code™ Approach”—Language features are presented in the context of a wide variety of complete working programs. Features thousands of lines of code in hundreds of complete working programs.
Enables students to confirm that programs run as expected. Students can also manipulate the code from the book's Companion Website ( and the authors' website (
Outstanding, consistent and applied pedagogy—Icons throughout identify Software Engineering Observations; Good Programming Practices; Common Programming Errors; Portability Tips; Performance Tips, Testing and Debugging Tips, and Look-and-Feel Observations.
Provides hundreds of valuable programming tips and facilitates learning.
Extensive set of interesting exercises and substantial projects.
Students can apply what they've learned in each chapter.
Extensive case studies.
Illustrates the more complex real-world examples.
Four-way syntax coloring with the use of two colors and shading.
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 or
Full chapter on Web accessibility for people with disabilities.
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.
Also available with the Multimedia Cyber Classroom in The Complete Python Training Course, Student Edition ; Web-based version: 0-13-067381-1).
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:

The full text, illustrations and program listings of its corresponding How to Program book with full-text searching and hyperlinking.
Hours of detailed, expert audio descriptions of thousands of lines of code that help to reinforce concepts.
An abundance of self-assessment material:
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).
Intuitive browser-based interface, designed to be easy and accessible for anyone who's ever used a Web browser.
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.

razi mahmood


Razi is an IT Lecturer and Training Consultant. His lecture/training includes:
+Software Engineering
+Mobile Development
+Web Portal System
+Adobe Creative Suites
+Microsoft Office Suites
Read more about him at About Page