Python in a Nutshell, 2nd Edition

Book description

This book offers Python programmers one place to look when they needhelp remembering or deciphering the syntax of this open source languageand its many powerful but scantily documented modules. Thiscomprehensive reference guide makes it easy to look up the mostfrequently needed information--not just about the Python languageitself, but also the most frequently used parts of the standard libraryand the most important third-party extensions.

Ask any Python aficionado and you'll hear that Python programmers haveit all: an elegant object-oriented language with readable andmaintainable syntax, that allows for easy integration with componentsin C, C++, Java, or C#, and an enormous collection of precoded standardlibrary and third-party extension modules. Moreover, Python is easy tolearn, yet powerful enough to take on the most ambitious programmingchallenges. But what Python programmers used to lack is a concise andclear reference resource, with the appropriate measure of guidance inhow best to use Python's great power. Python in aNutshell fills this need.

Python in a Nutshell, Second Edition covers morethan the language itself; it also deals with the mostfrequently used parts of the standard library, and the most popular andimportant third party extensions. Revised and expanded forPython 2.5, this book now contains the gory details of Python's newsubprocess module and breaking news about Microsoft's newIronPython project. Our "Nutshell" format fits Python perfectly bypresenting the highlights of the most important modules and functionsin its standard library, which cover over 90% of your practicalprogramming needs. This book includes:

  • A fast-paced tutorial on the syntax of the Python language
  • An explanation of object-oriented programming in Python
  • Coverage of iterators, generators, exceptions, modules,packages, strings, and regular expressions
  • A quick reference for Python's built-in types and functionsand key modules
  • Reference material on important third-party extensions,such as Numeric and Tkinter
  • Information about extending and embedding Python

Python in a Nutshell provides a solid,no-nonsense quick reference to information that programmers rely on themost. This book will immediately earn its place in any Pythonprogrammer's library.

Praise for the First Edition:

"In a nutshell, Python in a Nutshell serves oneprimary goal: to act as an immediately accessible goal for the Pythonlanguage. True, you can get most of the same core information that ispresented within the covers of this volume online, but this willinvariably be broken into multiple files, and in all likelihood lackingthe examples or the exact syntax description necessary to trulyunderstand a command."
--Richard Cobbett, Linux Format

"O'Reilly has several good books, of which Python in aNutshell by Alex Martelli is probably the best for giving yousome idea of what Python is about and how to do useful things with it."
--Jerry Pournelle, Byte Magazine

Publisher resources

View/Submit Errata

Table of contents

  1. Python in a Nutshell
  2. Preface
    1. How This Book Is Organized
      1. Part I, Getting Started with Python
      2. Part II, Core Python Language and Built-ins
      3. Part III, Python Library and Extension Modules
      4. Part IV, Network and Web Programming
      5. Part V, Extending and Embedding
    2. Conventions Used in This Book
      1. Reference Conventions
      2. Typographic Conventions
    3. Using Code Examples
    4. How to Contact Us
    5. Safari® Enabled
    6. Acknowledgments
  3. I. Getting Started with Python
    1. 1. Introduction to Python
      1. The Python Language
      2. The Python Standard Library and Extension Modules
      3. Python Implementations
        1. CPython
        2. Jython
        3. IronPython
        4. Choosing Between CPython, Jython, and IronPython
        5. PyPy and Other Experimental Versions
        6. Licensing and Price Issues
      4. Python Development and Versions
      5. Python Resources
        1. Documentation
        2. Newsgroups and Mailing Lists
        3. Special-Interest Groups
        4. Python Business Forum
        5. Python Journal
        6. Extension Modules and Python Sources
        7. The Python Cookbook
        8. Books and Magazines
    2. 2. Installation
      1. Installing Python from Source Code
        1. Windows
          1. Uncompressing and unpacking the Python source code
          2. Building the Python source code with Microsoft Visual Studio 2003
          3. Building Python for debugging
          4. Installing after the build
          5. Building Python for Cygwin
        2. Unix-Like Platforms
          1. Uncompressing and unpacking the Python source code
          2. Configuring, building, and testing
          3. Installing after the build
      2. Installing Python from Binaries
        1. Apple Macintosh
      3. Installing Jython
      4. Installing IronPython
    3. 3. The Python Interpreter
      1. The python Program
        1. Environment Variables
        2. Command-Line Syntax and Options
        3. Interactive Sessions
      2. Python Development Environments
        1. IDLE
        2. Other Free Cross-Platform Python IDEs
        3. Platform-Specific Free Python IDEs
        4. Commercial Python IDEs
        5. Free Text Editors with Python Support
        6. Tools for Checking Python Programs
      3. Running Python Programs
      4. The jython Interpreter
      5. The IronPython Interpreter
  4. II. Core Python Language and Built-ins
    1. 4. The Python Language
      1. Lexical Structure
        1. Lines and Indentation
        2. Character Sets
        3. Tokens
          1. Identifiers
          2. Keywords
          3. Operators
          4. Delimiters
          5. Literals
        4. Statements
          1. Simple statements
          2. Compound statements
      2. Data Types
        1. Numbers
          1. Integer numbers
          2. Floating-point numbers
          3. Complex numbers
        2. Sequences
          1. Iterables
          2. Strings
          3. Tuples
          4. Lists
        3. Sets
        4. Dictionaries
        5. None
        6. Callables
        7. Boolean Values
      3. Variables and Other References
        1. Variables
          1. Object attributes and items
          2. Accessing nonexistent references
        2. Assignment Statements
          1. Plain assignment
          2. Augmented assignment
        3. del Statements
      4. Expressions and Operators
        1. Comparison Chaining
        2. Short-Circuiting Operators
          1. The Python 2.5 ternary operator
      5. Numeric Operations
        1. Numeric Conversions
        2. Arithmetic Operations
          1. Division
          2. Exponentiation
        3. Comparisons
        4. Bitwise Operations on Integers
      6. Sequence Operations
        1. Sequences in General
          1. Sequence conversions
          2. Concatenation and repetition
          3. Membership testing
          4. Indexing a sequence
          5. Slicing a sequence
        2. Strings
        3. Tuples
        4. Lists
          1. Modifying a list
          2. In-place operations on a list
          3. List methods
          4. Sorting a list
      7. Set Operations
        1. Set Membership
        2. Set Methods
      8. Dictionary Operations
        1. Dictionary Membership
        2. Indexing a Dictionary
        3. Dictionary Methods
      9. The print Statement
      10. Control Flow Statements
        1. The if Statement
        2. The while Statement
        3. The for Statement
          1. Iterators
          2. range and xrange
          3. List comprehensions
        4. The break Statement
        5. The continue Statement
        6. The else Clause on Loop Statements
        7. The pass Statement
        8. The try and raise Statements
        9. The with Statement
      11. Functions
        1. The def Statement
        2. Parameters
        3. Attributes of Function Objects
          1. Docstrings
          2. Other attributes of function objects
        4. The return Statement
        5. Calling Functions
          1. The semantics of argument passing
          2. Kinds of arguments
        6. Namespaces
          1. The global statement
          2. Nested functions and nested scopes
        7. lambda Expressions
        8. Generators
          1. Generator expressions
          2. Generators in Python 2.5
        9. Recursion
    2. 5. Object-Oriented Python
      1. Classes and Instances
        1. Python Classes
        2. The class Statement
        3. The Class Body
          1. Attributes of class objects
          2. Function definitions in a class body
          3. Class-private variables
          4. Class documentation strings
        4. Descriptors
          1. Overriding and nonoverriding descriptors
        5. Instances
          1. _ _init_ _
          2. Attributes of instance objects
          3. The factory-function idiom
          4. _ _new_ _
        6. Attribute Reference Basics
          1. Getting an attribute from a class
          2. Getting an attribute from an instance
          3. Setting an attribute
        7. Bound and Unbound Methods
          1. Unbound method details
          2. Bound method details
        8. Inheritance
          1. Method resolution order
          2. Overriding attributes
          3. Delegating to superclass methods
          4. Cooperative superclass method calling
          5. “Deleting” class attributes
        9. The Built-in object Type
        10. Class-Level Methods
          1. Static methods
          2. Class methods
        11. Properties
          1. Why properties are important
          2. Properties and inheritance
        12. _ _slots_ _
        13. _ _getattribute_ _
        14. Per-Instance Methods
        15. Inheritance from Built-in Types
      2. Special Methods
        1. General-Purpose Special Methods
        2. Special Methods for Containers
          1. Sequences
          2. Mappings
          3. Sets
          4. Container slicing
          5. Container methods
        3. Special Methods for Numeric Objects
      3. Decorators
      4. Metaclasses
        1. How Python Determines a Class’s Metaclass
        2. How a Metaclass Creates a Class
          1. Defining and using your own metaclasses
          2. A substantial custom metaclass example
    3. 6. Exceptions
      1. The try Statement
        1. try/except
        2. try/finally
        3. Python 2.5 Exception-Related Enhancements
          1. The try/except/finally statement
          2. The with statement
          3. Generator enhancements
      2. Exception Propagation
      3. The raise Statement
      4. Exception Objects
        1. The Hierarchy of Standard Exceptions
        2. Standard Exception Classes
      5. Custom Exception Classes
        1. Custom Exceptions and Multiple Inheritance
        2. Other Exceptions Used in the Standard Library
      6. Error-Checking Strategies
        1. LBYL Versus EAFP
          1. Proper usage of EAFP
        2. Handling Errors in Large Programs
        3. Logging Errors
          1. The logging module
        4. The assert Statement
          1. The _ _debug_ _ built-in variable
    4. 7. Modules
      1. Module Objects
        1. The import Statement
          1. Module body
          2. Attributes of module objects
          3. Python built-ins
          4. Module documentation strings
          5. Module-private variables
        2. The from Statement
          1. The from ... import * statement
          2. from versus import
      2. Module Loading
        1. Built-in Modules
        2. Searching the Filesystem for a Module
        3. The Main Program
        4. The reload Function
        5. Circular Imports
        6. sys.modules Entries
        7. Custom Importers
          1. Rebinding _ _import_ _
          2. Import hooks
      3. Packages
        1. Special attributes of package objects
        2. Absolute Versus Relative Imports
      4. The Distribution Utilities (distutils)
        1. Python Eggs
    5. 8. Core Built-ins
      1. Built-in Types
      2. Built-in Functions
      3. The sys Module
      4. The copy Module
      5. The collections Module
        1. deque
        2. defaultdict
      6. The functional Module
      7. The bisect Module
      8. The heapq Module
      9. The UserDict Module
      10. The optparse Module
      11. The itertools Module
    6. 9. Strings and Regular Expressions
      1. Methods of String Objects
      2. The string Module
        1. Locale Sensitivity
        2. The maketrans Function
      3. String Formatting
        1. Format Specifier Syntax
        2. Common String-Formatting Idioms
        3. Template Strings
        4. Text Wrapping and Filling
      4. The pprint Module
      5. The repr Module
      6. Unicode
        1. The codecs Module
        2. The unicodedata Module
      7. Regular Expressions and the re Module
        1. Pattern-String Syntax
        2. Common Regular Expression Idioms
        3. Sets of Characters
        4. Alternatives
        5. Groups
        6. Optional Flags
        7. Match Versus Search
        8. Anchoring at String Start and End
        9. Regular Expression Objects
        10. Match Objects
        11. Functions of Module re
  5. III. Python Library and Extension Modules
    1. 10. File and Text Operations
      1. Other Chapters That Also Deal with Files
      2. Organization of This Chapter
      3. File Objects
        1. Creating a File Object with open
          1. File mode
          2. Binary and text modes
          3. Buffering
          4. Sequential and nonsequential access
        2. Attributes and Methods of File Objects
        3. Iteration on File Objects
        4. File-Like Objects and Polymorphism
        5. The tempfile Module
      4. Auxiliary Modules for File I/O
        1. The fileinput Module
        2. The linecache Module
        3. The struct Module
      5. The StringIO and cStringIO Modules
      6. Compressed Files
        1. The gzip Module
        2. The bz2 Module
        3. The tarfile Module
        4. The zipfile Module
        5. The zlib Module
      7. The os Module
        1. OSError Exceptions
        2. The errno Module
      8. Filesystem Operations
        1. Path-String Attributes of the os Module
        2. Permissions
        3. File and Directory Functions of the os Module
        4. The os.path Module
        5. The stat Module
        6. The filecmp Module
        7. The shutil Module
        8. File Descriptor Operations
      9. Text Input and Output
        1. Standard Output and Standard Error
        2. The print Statement
        3. Standard Input
        4. The getpass Module
      10. Richer-Text I/O
        1. The readline Module
        2. Console I/O
          1. The curses package
          2. The msvcrt Module
          3. The WConio and Console modules
      11. Interactive Command Sessions
        1. Initializing a Cmd Instance
        2. Methods of Cmd Instances
        3. Attributes of Cmd Instances
        4. A Cmd Example
      12. Internationalization
        1. The locale Module
        2. The gettext Module
          1. Using gettext for localization
          2. Essential gettext functions
        3. More Internationalization Resources
    2. 11. Persistence and Databases
      1. Serialization
        1. The marshal Module
          1. A marshaling example
        2. The pickle and cPickle Modules
          1. Functions of pickle and cPickle
          2. A pickling example
          3. Pickling instances
          4. Pickling customization with the copy_reg module
        3. The shelve Module
          1. A shelving example
      2. DBM Modules
        1. The anydbm Module
        2. The dumbdbm Module
        3. The dbm, gdbm, and dbhash Modules
        4. The whichdb Module
        5. Examples of DBM-Like File Use
      3. Berkeley DB Interfacing
        1. Simplified and Complete BSD DB Python Interfaces
        2. Module bsddb
        3. Examples of Berkeley DB Use
      4. The Python Database API (DBAPI) 2.0
        1. Exception Classes
        2. Thread Safety
        3. Parameter Style
        4. Factory Functions
        5. Type Description Attributes
        6. The connect Function
        7. Connection Objects
        8. Cursor Objects
        9. DBAPI-Compliant Modules
        10. Gadfly
        11. SQLite
    3. 12. Time Operations
      1. The time Module
      2. The datetime Module
        1. Class date
        2. Class time
        3. Class datetime
        4. Class timedelta
      3. The pytz Module
      4. The dateutil Module
      5. The sched Module
      6. The calendar Module
      7. The mx.DateTime Module
        1. Date and Time Types
        2. The DateTime Type
          1. Factory functions for DateTime
          2. Methods of DateTime instances
          3. Attributes of DateTime instances
          4. Arithmetic on DateTime instances
        3. The DateTimeDelta Type
          1. Factory functions for DateTimeDelta
          2. Methods of DateTimeDelta instances
          3. Attributes of DateTimeDelta instances
          4. Arithmetic on DateTimeDelta instances
        4. Other Attributes
        5. Submodules
    4. 13. Controlling Execution
      1. Dynamic Execution and the exec Statement
        1. Avoiding exec
        2. Expressions
        3. Compile and Code Objects
        4. Never exec nor eval Untrusted Code
      2. Internal Types
        1. Type Objects
        2. The Code Object Type
        3. The frame Type
      3. Garbage Collection
        1. The gc Module
        2. The weakref Module
      4. Termination Functions
      5. Site and User Customization
        1. The site and sitecustomize Modules
        2. User Customization
    5. 14. Threads and Processes
      1. Threads in Python
      2. The thread Module
      3. The Queue Module
        1. Methods of Queue Instances
        2. Customizing Class Queue by Subclassing
      4. The threading Module
        1. Thread Objects
        2. Thread Synchronization Objects
          1. Timeout parameters
          2. Lock and RLock objects
          3. Condition objects
          4. Event objects
          5. Semaphore objects
        3. Thread Local Storage
      5. Threaded Program Architecture
      6. Process Environment
      7. Running Other Programs
        1. Running Other Programs with the os Module
        2. The Subprocess Module
          1. What to run, and how: args, executable, shell
          2. Subprocess files: stdin, stdout, stderr, bufsize, universal_newlines, close_fds
          3. Other arguments: preexec_fn, cwd, env, startupinfo, creationflags
          4. Attributes of subprocess.Popen instances
          5. Methods of subprocess.Popen instances
      8. The mmap Module
        1. Methods of mmap Objects
        2. Using mmap Objects for IPC
    6. 15. Numeric Processing
      1. The math and cmath Modules
      2. The operator Module
      3. Random and Pseudorandom Numbers
        1. Physically random and cryptographically strong random numbers
        2. The random module
      4. The decimal Module
      5. The gmpy Module
    7. 16. Array Processing
      1. The array Module
      2. Extensions for Numeric Array Computation
      3. The Numeric Package
      4. Array Objects
        1. Typecodes
        2. Shape and Indexing
        3. Storage
        4. Slicing
          1. Slicing examples
          2. Assigning to array slices
        5. Truth Values and Comparisons of Arrays
        6. Factory Functions
        7. Attributes and Methods
        8. Operations on Arrays
          1. Broadcasting
          2. In-place operations
        9. Functions
      5. Universal Functions (ufuncs)
        1. The Optional output Argument
        2. Callable Attributes
        3. ufunc Objects Supplied by Numeric
        4. Shorthand for Commonly Used ufunc Methods
      6. Auxiliary Numeric Modules
    8. 17. Tkinter GUIs
      1. Tkinter Fundamentals
        1. Dialogs
          1. The tkMessageBox module
          2. The tkSimpleDialog module
          3. The tkFileDialog module
          4. The tkColorChooser module
      2. Widget Fundamentals
        1. Common Widget Options
          1. Color options
          2. Length options
          3. Options expressing numbers of characters
          4. Other common options
        2. Common Widget Methods
        3. Tkinter Variable Objects
        4. Tkinter Images
      3. Commonly Used Simple Widgets
        1. Button
        2. Checkbutton
        3. Entry
        4. Label
        5. Listbox
        6. Radiobutton
        7. Scale
        8. Scrollbar
      4. Container Widgets
        1. Frame
        2. Toplevel
      5. Menus
        1. Menu-Specific Methods
        2. Menu Entries
        3. Menu Example
      6. The Text Widget
        1. The ScrolledText Module
        2. Text Widget Methods
        3. Marks
        4. Tags
        5. Indices
        6. Fonts
        7. Text Example
      7. The Canvas Widget
        1. Canvas Methods on Items
        2. The Line Canvas Item
        3. The Polygon Canvas Item
        4. The Rectangle Canvas Item
        5. The Text Canvas Item
        6. A Simple Plotting Example
      8. Layout Management
        1. The Packer
        2. The Gridder
        3. The Placer
      9. Tkinter Events
        1. The Event Object
        2. Binding Callbacks to Events
        3. Event Names
          1. Keyboard events
          2. Mouse events
        4. Event-Related Methods
        5. An Events Example
        6. Other Callback-Related Methods
    9. 18. Testing, Debugging, and Optimizing
      1. Testing
        1. Unit Testing and System Testing
        2. The doctest Module
        3. The unittest Module
          1. The TestCase class
          2. Unit tests dealing with large amounts of data
      2. Debugging
        1. Before You Debug
        2. The inspect Module
          1. An example of using inspect
        3. The traceback Module
        4. The pdb Module
        5. Debugging in IDLE
      3. The warnings Module
        1. Classes
        2. Objects
        3. Filters
        4. Functions
      4. Optimization
        1. Developing a Fast-Enough Python Application
        2. Benchmarking
        3. Large-Scale Optimization
          1. List operations
          2. String operations
          3. Dictionary operations
          4. Set operations
          5. Summary of big-O times for operations on Python built-in types
        4. Profiling
          1. The profile module
          2. Calibration
          3. The pstats module
        5. Small-Scale Optimization
          1. Module timeit
          2. Building up a string from pieces
          3. Searching and sorting
          4. Avoiding exec and from...import *
          5. Optimizing loops
          6. Optimizing I/O
  6. IV. Network and Web Programming
    1. 19. Client-Side Network Protocol Modules
      1. URL Access
        1. The urlparse Module
        2. The urllib Module
          1. Functions
          2. The FancyURLopener class
        3. The urllib2 Module
          1. Functions
          2. The Request class
          3. The OpenerDirector class
          4. Handler classes
          5. Handling authentication
      2. Email Protocols
        1. The poplib Module
        2. The smtplib Module
      3. The HTTP and FTP Protocols
        1. The httplib Module
        2. The ftplib Module
      4. Network News
        1. Response Strings
        2. Methods
        3. Example
      5. Telnet
      6. Distributed Computing
      7. Other Protocols
    2. 20. Sockets and Server-Side Network Protocol Modules
      1. The socket Module
        1. socket Functions
        2. The socket Class
        3. Echo Server and Client Using TCP Sockets
        4. Echo Server and Client Using UDP Sockets
        5. Socket Timeout Behavior
      2. The SocketServer Module
        1. The BaseRequestHandler Class
        2. HTTP Servers
          1. The BaseHTTPServer module
          2. The SimpleHTTPServer module
          3. The CGIHTTPServer module
          4. The SimpleXMLRPCServer module
      3. Event-Driven Socket Programs
        1. The select Module
        2. The asyncore and asynchat Modules
          1. The asyncore module
          2. The asynchat module
        3. The Twisted Framework
          1. The twisted.internet and twisted.protocols packages
          2. Reactors
          3. Transports
          4. Protocol handlers and factories
          5. Echo server using Twisted
    3. 21. CGI Scripting and Alternatives
      1. CGI in Python
        1. Form Submission Methods
        2. The cgi Module
        3. CGI Output and Errors
          1. Error messages
          2. The cgitb module
        4. Installing Python CGI Scripts
          1. Python CGI scripts on Microsoft web servers
          2. Python CGI scripts on Apache
          3. Python CGI scripts on Xitami
      2. Cookies
        1. The Cookie Module
          1. Cookie methods
          2. Morsel attributes and methods
          3. Using module Cookie
      3. Other Server-Side Approaches
        1. FastCGI
        2. WSGI
        3. mod_python
        4. Custom Pure Python Servers
        5. Other Higher-Level-of-Abstraction Frameworks
          1. Webware
          2. Quixote
          3. web.py
    4. 22. MIME and Network Encodings
      1. Encoding Binary Data as Text
        1. The base64 Module
        2. The quopri Module
        3. The uu Module
      2. MIME and Email Format Handling
        1. Functions in Package email
        2. The email.Message Module
        3. The email.Generator Module
        4. Creating Messages
        5. The email.Encoders Module
        6. The email.Utils Module
        7. Example Uses of the email Package
        8. The Message Classes of the rfc822 and mimetools Modules
    5. 23. Structured Text: HTML
      1. The sgmllib Module
        1. Parsing HTML with sgmllib
      2. The htmllib Module
        1. The htmlentitydefs Module
        2. Parsing HTML with htmllib
      3. The HTMLParser Module
        1. Parsing HTML with HTMLParser
      4. The BeautifulSoup Extension
        1. Parsing HTML with BeautifulSoup
      5. Generating HTML
        1. Embedding
        2. Templating
        3. The Cheetah Package
          1. The Cheetah templating language
          2. The Template class
          3. A Cheetah example
    6. 24. Structured Text: XML
      1. An Overview of XML Parsing
      2. Parsing XML with SAX
        1. The xml.sax Package
          1. Attributes
          2. Incremental parsing
          3. The xml.sax.saxutils module
        2. Parsing XHTML with xml.sax
      3. Parsing XML with DOM
        1. The xml.dom Package
        2. The xml.dom.minidom Module
          1. Node objects
          2. Attr objects
          3. Document objects
          4. Element objects
        3. Parsing XHTML with xml.dom.minidom
        4. The xml.dom.pulldom Module
        5. Parsing XHTML with xml.dom.pulldom
      4. Changing and Generating XML
        1. Factory Methods of a Document Object
        2. Mutating Methods of an Element Object
        3. Mutating Methods of a Node Object
        4. Output Methods of a Node Object
        5. Changing and Outputting XHTML with xml.dom.minidom
  7. V. Extending and Embedding
    1. 25. Extending and Embedding Classic Python
      1. Extending Python with Python’s C API
        1. Building and Installing C-Coded Python Extensions
          1. The C compiler you need
          2. Compatibility of C-coded extensions among Python versions
        2. Overview of C-Coded Python Extension Modules
        3. Return Values of Python’s C API Functions
        4. Module Initialization
          1. The PyMethodDef structure
        5. Reference Counting
        6. Accessing Arguments
        7. Creating Python Values
        8. Exceptions
        9. Abstract Layer Functions
        10. Concrete Layer Functions
        11. A Simple Extension Example
        12. Defining New Types
          1. Per-instance data
          2. The PyTypeObject definition
          3. Instance initialization and finalization
          4. Attribute access
          5. Type definition example
      2. Extending Python Without Python’s C API
      3. Embedding Python
        1. Installing Resident Extension Modules
        2. Setting Arguments
        3. Python Initialization and Finalization
        4. Running Python Code
      4. Pyrex
        1. The cdef Statement and Function Parameters
          1. External declarations
          2. cdef classes
        2. The ctypedef Statement
        3. The for...from Statement
        4. Pyrex Expressions
        5. A Pyrex Example: Greatest Common Divisor
    2. 26. Extending and Embedding Jython
      1. Importing Java Packages in Jython
        1. The Jython Registry
        2. Accessibility
        3. Type Conversions
          1. Calling overloaded Java methods
          2. The jarray module
          3. The java.util collection classes
        4. Subclassing a Java Class
        5. JavaBeans
      2. Embedding Jython in Java
        1. The PythonInterpreter Class
          1. The _ _builtin_ _ class
        2. The PyObject Class
        3. The Py Class
      3. Compiling Python into Java
        1. The jythonc Command
        2. Adding Java-Visible Methods
        3. Python Applets and Servlets
          1. Python applets
          2. Python servlets
    3. 27. Distributing Extensions and Programs
      1. Python’s distutils
        1. The Distribution and Its Root
        2. The setup.py Script
        3. Metadata About the Distribution
        4. Distribution Contents
          1. Python source files
          2. Datafiles
          3. C-coded extensions
        5. The setup.cfg File
        6. The MANIFEST.in and MANIFEST Files
        7. Creating Prebuilt Distributions with distutils
      2. py2exe
      3. py2app
      4. cx_Freeze
      5. PyInstaller
  8. A. About the Author
  9. Index
  10. About the Author
  11. Colophon
  12. Copyright

Product information

  • Title: Python in a Nutshell, 2nd Edition
  • Author(s): Alex Martelli
  • Release date: July 2006
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9780596100469