Python in a Nutshell. 2nd Edition - Helion
ISBN: 978-14-493-7910-0
stron: 738, Format: ebook
Data wydania: 2006-07-14
Księgarnia: Helion
Cena książki: 118,15 zł (poprzednio: 137,38 zł)
Oszczędzasz: 14% (-19,23 zł)
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
Osoby które kupowały "Python in a Nutshell. 2nd Edition", wybierały także:
- GraphQL. Kurs video. Buduj nowoczesne API w Pythonie 169,00 zł, (50,70 zł -70%)
- Receptura na Python. Kurs Video. 54 praktyczne porady dla programist 199,00 zł, (59,70 zł -70%)
- Podstawy Pythona z Minecraftem. Kurs video. Piszemy pierwsze skrypty 149,00 zł, (44,70 zł -70%)
- Twórz gry w Pythonie. Kurs video. Poznaj bibliotekę PyGame 249,00 zł, (74,70 zł -70%)
- Data Science w Pythonie. Kurs video. Algorytmy uczenia maszynowego 199,00 zł, (59,70 zł -70%)
Spis treści
Python in a Nutshell. 2nd Edition eBook -- spis treści
- 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
- How This Book Is Organized
- 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
- Windows
- Installing Python from Binaries
- Apple Macintosh
- Installing Jython
- Installing IronPython
- Installing Python from Source Code
- 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
- The python Program
- 1. Introduction to Python
- 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
- Numbers
- Variables and Other References
- Variables
- Object attributes and items
- Accessing nonexistent references
- Assignment Statements
- Plain assignment
- Augmented assignment
- del Statements
- Variables
- 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
- Sequences in General
- 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
- Lexical Structure
- 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 Classs Metaclass
- How a Metaclass Creates a Class
- Defining and using your own metaclasses
- A substantial custom metaclass example
- Classes and Instances
- 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
- LBYL Versus EAFP
- The try Statement
- 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
- The import Statement
- 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
- Module Objects
- 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
- 4. The Python Language
- 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
- Creating a File Object with open
- 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
- The marshal Module
- 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
- Serialization
- 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
- Dynamic Execution and the exec Statement
- 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
- Dialogs
- 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
- Common Widget Options
- 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
- Tkinter Fundamentals
- 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
- Testing
- 10. File and Text Operations
- 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
- URL Access
- 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
- The socket Module
- 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
- The Cookie Module
- Other Server-Side Approaches
- FastCGI
- WSGI
- mod_python
- Custom Pure Python Servers
- Other Higher-Level-of-Abstraction Frameworks
- Webware
- Quixote
- web.py
- CGI in Python
- 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
- Encoding Binary Data as Text
- 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
- The sgmllib Module
- 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
- The xml.sax Package
- 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
- 19. Client-Side Network Protocol Modules
- V. Extending and Embedding
- 25. Extending and Embedding Classic Python
- Extending Python with Pythons 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 Pythons 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
- Building and Installing C-Coded Python Extensions
- Extending Python Without Pythons 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
- The cdef Statement and Function Parameters
- Extending Python with Pythons C API
- 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
- The PythonInterpreter Class
- Compiling Python into Java
- The jythonc Command
- Adding Java-Visible Methods
- Python Applets and Servlets
- Python applets
- Python servlets
- Importing Java Packages in Jython
- 27. Distributing Extensions and Programs
- Pythons 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
- Pythons distutils
- 25. Extending and Embedding Classic Python
- A. About the Author
- Index
- About the Author
- Colophon
- Copyright