Cover image for Python Pocket Reference, 5th Edition

Book description

Updated for both Python 3.4 and 2.7, this convenient pocket guide is the perfect on-the-job quick reference. You’ll find concise, need-to-know information on Python types and statements, special method names, built-in functions and exceptions, commonly used standard library modules, and other prominent Python tools. The handy index lets you pinpoint exactly what you need.

Table of Contents

  1. 1. Python Pocket Reference
    1. Introduction
    2. Book Conventions
    3. Python Command-Line Usage
      1. Python Command Options
      2. Command-Line Program Specification
      3. Python 2.X Command Options
    4. Python Environment Variables
      1. Operational Variables
      2. Python Command Option Variables
    5. Python Windows Launcher Usage
      1. Launcher File Directives
      2. Launcher Command Lines
      3. Launcher Environment Variables
    6. Built-in Types and Operators
      1. Operators and Precedence
        1. Atomic terms and dynamic typing
      2. Operator Usage Notes
      3. Operations by Category
      4. Sequence Operation Notes
    7. Specific Built-in Types
      1. Numbers
        1. Literals and creation
        2. Operations
        3. Decimal and fraction
        4. Other numeric types
      2. Strings
        1. Literals and creation
        2. Operations
        3. String formatting
        4. String formatting expression
        5. Formatting expression syntax
        6. String formatting method
        7. Formatting method syntax
        8. Template string substitution
        9. String methods
        10. byte and bytearray methods
        11. Searching methods
        12. Splitting and joining methods
        13. Formatting methods
        14. Content test methods
        15. The original string module
      3. Unicode Strings
        1. Unicode support in Python 3.X
        2. byte and bytearray strings
        3. Unicode support in Python 2.X
      4. Lists
        1. Literals and creation
        2. Operations
        3. List comprehension expressions
        4. The iteration protocol
        5. Generator expressions
        6. Other comprehension expressions
      5. Dictionaries
        1. Literals and creation
        2. Operations
      6. Tuples
        1. Literals and creation
        2. Operations
      7. Files
        1. Input files
        2. Output files
        3. Any files
        4. Other file attributes (some read-only)
        5. File context managers
        6. File usage notes
      8. Sets
        1. Literals and creation
        2. Operations
      9. Other Types and Conversions
        1. Boolean
        2. Type Conversions
    8. Statements and Syntax
      1. Syntax Rules
      2. Name Rules
        1. Name format
        2. Name conventions
    9. Specific Statements
      1. The Assignment Statement
        1. Augmented assignment
        2. Normal sequence assignment
        3. Extended sequence assignment (3.X)
      2. The Expression Statement
        1. Call syntax
        2. Arbitrary arguments call syntax
      3. The print Statement
        1. Python 2.X print statements
      4. The if Statement
      5. The while Statement
      6. The for Statement
      7. The pass Statement
      8. The break Statement
      9. The continue Statement
      10. The del Statement
      11. The def Statement
        1. Python 3.X keyword-only arguments
        2. Python 3.X function annotations
        3. lambda expressions
        4. Function defaults and attributes
        5. Function and method decorators
      12. The return Statement
      13. The yield Statement
        1. Generator function changes in Python 3.3
      14. The global Statement
      15. The nonlocal Statement
      16. The import Statement
        1. Package imports
        2. Python 3.3 namespace packages
        3. Import algorithm
      17. The from Statement
        1. Package relative import syntax
      18. The class Statement
        1. Class decorators in Python 3.X, 2.6, and 2.7
        2. Metaclasses
      19. The try Statement
        1. Python 2.X try statement forms
      20. The raise Statement
        1. Python 3.X chained exceptions
        2. Class exceptions
        3. Python 2.X raise statement forms
      21. The assert Statement
      22. The with Statement
        1. Multiple context managers in Python 3.1 and 2.7
        2. Context manager protocol
      23. Python 2.X Statements
    10. Namespace and Scope Rules
      1. Qualified Names: Object Namespaces
      2. Unqualified Names: Lexical Scopes
      3. Nested Scopes and Closures
        1. Enclosing scopes and defaults
    11. Object-Oriented Programming
      1. Classes and Instances
        1. Class objects provide default behavior
        2. Instance objects are generated from classes
        3. Inheritance rules
      2. Pseudoprivate Attributes
        1. Module privates
        2. Class privates
      3. New-Style Classes
      4. Formal Inheritance Rules
        1. Classic classes: DFLR
        2. New-style classes: MRO
        3. Example: nondiamonds
        4. Example: diamonds
        5. New-style inheritance algorithm
        6. New-style precedence and context
    12. Operator Overloading Methods
      1. Methods for All Types
      2. Methods for Collections (Sequences, Mappings)
      3. Methods for Numbers (Binary Operators)
        1. Basic binary methods
        2. Right-side binary methods
        3. Augmented binary methods
      4. Methods for Numbers (Other Operations)
      5. Methods for Descriptors
      6. Methods for Context Managers
      7. Python 2.X Operator Overloading Methods
        1. Methods in Python 3.X only
        2. Methods in Python 2.X only
    13. Built-in Functions
      1. Python 2.X Built-in Functions
        1. Python 3.X built-ins not supported by Python 2.X
        2. Python 2.X built-ins not supported by Python 3.X
    14. Built-in Exceptions
      1. Superclasses: Categories
      2. Specific Exceptions
      3. Specific OSError Exceptions
      4. Warning Category Exceptions
      5. Warnings Framework
      6. Python 3.2 Built-in Exceptions
      7. Python 2.X Built-in Exceptions
    15. Built-in Attributes
    16. Standard Library Modules
    17. The sys Module
    18. The string Module
      1. Functions and Classes
      2. Constants
    19. The os System Module
      1. Administrative Tools
      2. Portability Constants
      3. Shell Commands
      4. Environment Tools
      5. File Descriptor Tools
      6. File Pathname Tools
      7. Process Control
      8. The os.path Module
    20. The re Pattern-Matching Module
      1. Module Functions
      2. Regular Expression Objects
      3. Match Objects
      4. Pattern Syntax
    21. Object Persistence Modules
      1. The shelve and dbm Modules
        1. File opens
        2. File operations
      2. The pickle Module
        1. Pickling interfaces
        2. Unpickling interfaces
        3. pickle usage notes
    22. The tkinter GUI Module and Tools
      1. tkinter Example
      2. tkinter Core Widgets
      3. Common Dialog Calls
        1. Module tkinter.messagebox (tkMessageBox in Python 2.X)
        2. Module tkinter.simpledialog (tkSimpleDialog in Python 2.X)
        3. Module tkinter.colorchooser (tkColorChooser in Python 2.X)
        4. Module tkinter.filedialog (tkFileDialog in Python 2.X)
      4. Additional tkinter Classes and Tools
      5. Tcl/Tk-to-Python/tkinter Mappings
    23. Internet Modules and Tools
    24. Other Standard Library Modules
      1. The math Module
      2. The time Module
      3. The timeit Module
      4. The datetime Module
      5. The random Module
      6. The json Module
      7. The subprocess Module
      8. The enum Module
      9. The struct Module
      10. Threading Modules
    25. Python SQL Database API
      1. API Usage Example
      2. Module Interface
      3. Connection Objects
      4. Cursor Objects
      5. Type Objects and Constructors
    26. More Hints and Idioms
      1. Core Language Hints
      2. Environment Hints
      3. Usage Hints
      4. Assorted Hints
  2. Index
  3. Copyright