You are previewing Core Python Programming.
O'Reilly logo
Core Python Programming

Book Description

  • New to Python? This is the developer's guide to Python development!

  • Learn the core features of Python as well as advanced topics such as regular expressions, multithreaded programming, Web/Internet and network development, GUI development with Tk(inter) and more

  • Also includes features found in the new Python 1.6 and 2.0 releases

  • CD-ROM: Complete Python distributions (source code, documentation, and various binaries) plus all example scripts in the book

  • Python is an Internet and systems programming language that is soaring in popularity in today's fast-paced software development environment, and no wonder: it's simple (yet robust), object-oriented (yet can be used as a procedural language), extensible, scalable and features an easy to learn syntax that is clear and concise. Python combines the power of a compiled object language like Java and C++ with the ease of use and rapid development time of a scripting language. In fact, it's syntax is so easy to understand that you are more likely to pick it up faster than any of the other popular scripting languages in use today!

    In Core Python Programming, Internet software engineer and technical trainer Wesley Chun provides intermediate and experienced developers all they need to know to learn Python-fast. Like all Core Series books, Core Python Programming delivers hundreds of industrial-strength code snippets and examples, all targeted at professional developers who want to leverage their existing skills! In particular, Core Python Programming presents numerous interactive examples that can be entered into the Python interpreter right in front of you! Finally, we present a chapter that shows you step-by-step how to extend Python using C or C++.

  • Python syntax and style

  • Development and Run-time Environments

  • Objects and Python memory management

  • Standard data types, methods, and operators

  • Loops and conditionals

  • Files and Input/Output

  • Exceptions and error handling

  • Functions, scope, arguments, and functional programming

  • Importing modules and module attributes

  • Object-oriented Programming with classes, methods, and instances

  • Callable Objects

  • Extending Python

  • Coverage of the Python standard module library and client-server application development includes comprehensive introductions to the following topics in Python programming:

  • Regular expressions

  • TCP/IP and UDP/IP Network programming using sockets

  • Operating system interface

  • GUI development with Tk using Tkinter

  • Multithreaded programming

  • Interactive Web/CGI/Internet applications

  • Executing code in a restricted environment

  • Inheritance, type emulation, operator overloading, and delegation in an OOP environment

  • Finally, we provide an introduction to the new features introduced in Python 1.6. These include Unicode string support, the new function invocation syntax which lets the caller provide a tuple of positional arguments and/or a dictionary of keyword arguments, and the new string methods. We also provide a glimpse into features that will only be found in the newer 2.0 release.

    Every Core Series book:

  • DEMONSTRATES how to write commercial-quality code

  • FEATURES dozens of programs and examples!

  • FOCUSES on the features and functions most important to real developers

  • PROVIDES objective, unbiased coverage of cutting-edge technologies-no

  • hype!

  • Core Python Programming delivers:

  • Coverage of the core parts of the Python language

  • Real-world insights for developing Web/Internet, network, multithreaded and GUI applications

  • Tables and charts detailing Python modules, built-in functions, operators, and attributes

  • Code snippets to try live with Python's interactive interpreter, hammering the concepts home

  • Extensive code examples-including several complete sample applications

  • CD-ROM includes complete Python source code and documentation distributions for Unix/Linux along with binaries for Windows and Macintosh platforms plus source code for all examples in the book.

    Table of Contents

    1. Copyright
    2. Welcome to Python!
    3. Acknowledgements
    4. Core Python
      1. Welcome to Python!
        1. What Is Python?
        2. History of Python
        3. Features of Python
        4. Obtaining Python
        5. Obtaining Python
        6. Installing Python
        7. Running Python
        8. Python Documentation
        9. Comparing Python
        10. JPython and Some Nomenclature
        11. Exercises
      2. Getting Started
        1. Program Output, the print Statement, and “Hello World!”
        2. Program Input and the raw_input() Built-in Function
        3. Comments
        4. Operators
        5. Variables and Assignment
        6. Numbers
        7. Strings
        8. Lists and Tuples
        9. Dictionaries
        10. Code Blocks Use Indentation
        11. if Statement
        12. while Loop
        13. for Loop and the range() Built-in Function
        14. Files and the open() Built-in Function
        15. Errors and Exceptions
        16. Functions
        17. Classes
        18. Modules
        19. Exercises
      3. Syntax and Style
        1. Statements and Syntax
        2. Variable Assignment
        3. Identifiers
        4. Basic Style Guidelines
        5. Memory Management
        6. First Python Application
        7. Exercises
      4. Python Objects
        1. Python Objects
        2. Standard Types
        3. Other Built-in Types
        4. Internal Types
        5. Standard Type Operators
        6. Standard Type Built-in Functions
        7. Categorizing the Standard Types
        8. Unsupported Types
        9. Exercises
      5. Numbers
        1. Introduction to Numbers
        2. Integers
        3. Floating Point Real Numbers
        4. Complex Numbers
        5. Operators
        6. Built-in Functions
        7. Related Modules
        8. Exercises
      6. Sequences: Strings, Lists, and Tuples
        1. Sequences
        2. Strings
        3. Strings and Operators
        4. String-only Operators
        5. Built-in Functions
        6. String Built-in Methods
        7. Special Features of Strings
        8. Related Modules
        9. Summary of String Highlights
        10. Lists
        11. Operators
        12. Built-in Functions
        13. List Type Built-in Methods
        14. Special Features of Lists
        15. Tuples
        16. Tuple Operators and Built-in Functions
        17. Special Features of Tuples
        18. Related Modules
        19. *Shallow and Deep Copies
        20. Exercises
      7. Dictionaries
        1. Introduction to Dictionaries
        2. Operators
        3. Built-in Functions
        4. Built-in Methods
        5. Dictionary Keys
        6. Exercises
      8. Conditionals and Loops
        1. if statement
        2. else Statement
        3. elif (a.k.a. else-if) Statement
        4. while Statement
        5. for Statement
        6. break Statement
        7. continue Statement
        8. pass Statement
        9. else Statement… Take Two
        10. Exercises
      9. Files and Input/Output
        1. File Objects
        2. File Built-in Function [open()]
        3. File Built-in Methods
        4. File Built-in Attributes
        5. Standard Files
        6. Command-line Arguments
        7. File System
        8. File Execution
        9. Persistent Storage Modules
        10. Related Modules
        11. Exercises
      10. Errors And Exceptions
        1. What Are Exceptions?
        2. Exceptions in Python
        3. Detecting and Handling Exceptions
        4. *Exceptions as Strings
        5. *Exceptions as Classes
        6. Raising Exceptions
        7. Assertions
        8. Standard Exceptions
        9. *Creating Exceptions
        10. Why Exceptions (Now)?
        11. Why Exceptions at All?
        12. Exceptions and the sys Module
        13. Related Modules
        14. Exercises
      11. Functions
        1. What Are Functions?
        2. Calling Functions
        3. Creating Functions
        4. Passing Functions
        5. Formal Arguments
        6. Positional Arguments
        7. Default Arguments
        8. Why Default Arguments?
        9. Default Function Object Argument Example
        10. Variable-length Arguments
        11. Non-keyword Variable Arguments (Tuple)
        12. Keyword Variable Arguments (Dictionary)
        13. Calling Functions with Variable Argument Objects
        14. Functional Programming
        15. Anonymous Functions and lambda
        16. Built-in Functions: apply(), filter(), map(), reduce()
        17. *apply()
        18. Lines 1 - 4
        19. Lines 6 - 7
        20. Lines 9 - 28
        21. Lines 30-41
        22. filter()
        23. map()
        24. reduce()
        25. Variable Scope
        26. *Recursion
        27. Exercises
      12. Modules
        1. What are Modules?
        2. Modules and Files
        3. Namespaces
        4. Importing Modules
        5. Importing Module Attributes
        6. Module Built-in Functions
        7. Packages
        8. Other Features of Modules
        9. Exercises
      13. Classes and OOP
        1. Introduction
        2. Object-oriented Programming
        3. Classes
        4. Class Attributes
        5. Instances
        6. Instance Attributes
        7. Binding and Method Invocation
        8. Composition
        9. Subclassing and Derivation
        10. Inheritance
        11. Built-in Functions for Classes, Instances, and Other Objects
        12. Type vs. Classes/Instances
        13. Customizing Classes with Special Methods
        14. Privacy
        15. Delegation
        16. Related Modules and Documentation
        17. Exercises
      14. Execution Environment
        1. Callable Objects
        2. Code Objects
        3. Executable Object Statements and Built-in Functions
        4. Executing Other (Python) Programs
        5. Executing Other (Non-Python) Programs
        6. Restricted Execution
        7. Terminating Execution
        8. Related Modules
        9. Exercises
    5. Advanced Topics
      1. Regular Expressions
        1. Introduction/Motivation
        2. Special Symbols and Characters for REs
        3. REs and Python
        4. Regular Expression Adventures
        5. Exercises
      2. Network Programming
        1. Introduction
        2. Sockets: Communication Endpoints
        3. Network Programming in Python
        4. Related Modules
        5. Exercises
      3. Multithreaded Programming
        1. Introduction/Motivation
        2. Threads and Processes
        3. Threads and Python
        4. thread Module
        5. threading Module
        6. Exercises
      4. GUI Programming with Tkinter
        1. Introduction
        2. Tkinter and Python Programming
        3. Tkinter Examples
        4. Related Modules and Other GUIs
        5. Exercises
      5. Web Programming
        1. Introduction
        2. Web Surfing with Python: Creating Simple Web Clients
        3. Advanced Web Clients
        4. CGI: Helping Web Servers Process Client Data
        5. Building CGI Application
        6. Advanced CGI
        7. Web (HTTP) Servers
        8. Related Modules
        9. Exercises
      6. Extending Python
        1. Introduction/Motivation
        2. Related Topics
        3. Exercises
    6. Answers to Selected Exercises
    7. Other Reading and References
      1. Printed References
      2. Other Printed References
      3. Online References
    8. Python Operator Summary
    9. What's New in Python 2.0?
      1. Introduction
      2. Review and Preview
      3. Augmented Assignment
      4. List Comprehensions
      5. Extended import Statement
      6. Extended print Statement
      7. Conclusion
      8. Exercise