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