Learning Python. Powerful Object-Oriented Programming. 4th Edition (ebook)(audiobook)(audiobook)


- Ocena:
- Bądź pierwszym, który oceni tę książkę
- Stron:
- 1216
- 2w1 w pakiecie:
-
ePubMobi
Opis książki
Google and YouTube use Python because it's highly adaptable, easy to maintain, and allows for rapid development. If you want to write high-quality, efficient code that's easily integrated with other languages and tools, this hands-on book will help you be productive with Python quickly -- whether you're new to programming or just new to Python. It's an easy-to-follow self-paced tutorial, based on author and Python expert Mark Lutz's popular training course.
Each chapter contains a stand-alone lesson on a key component of the language, and includes a unique Test Your Knowledge section with practical exercises and quizzes, so you can practice new skills and test your understanding as you go. You'll find lots of annotated examples and illustrations to help you get started with Python 3.0.
Learn about Python's major built-in object types, such as numbers, lists, and dictionariesCreate and process objects using Python statements, and learn Python's general syntax modelStructure and reuse code using functions, Python's basic procedural toolLearn about Python modules: packages of statements, functions, and other tools, organized into larger componentsDiscover Python's object-oriented programming tool for structuring codeLearn about the exception-handling model, and development tools for writing larger programsExplore advanced Python tools including decorators, descriptors, metaclasses, and Unicode processing
O autorze
1 Mark LutzMark Lutz — to znany na całym świecie instruktor Pythona, autor najwcześniejszych oraz najlepiej sprzedających się tekstów poświęconych temu językowi i jedna z najważniejszych postaci w środowisku Pythona. Poza poprzednimi wydaniami tej książki — w tym przetłumaczonej na język polski wersji „Python. Wprowadzenie” (Helion, 2002), napisał także „Programming Python” oraz „Python Pocket Reference”. Osobiście używa języka Python i promuje go od 1992 roku. Książki na temat tego języka zaczął publikować w 1995 roku, zaś szkolenia z Pythona prowadzi od 1997 roku. Do początku roku 2008 przeprowadził ponad dwieście sesji treningowych poświęconych temu językowi.
Kup polskie wydanie:
Podobne produkty
-
Czysty kod. Podręcznik dobrego programisty Czysty kod. Podręcznik dobrego programisty
Robert C. Martin
-
Mistrz czystego kodu. Kodeks postępowania profe... Mistrz czystego kodu. Kodeks postępowania profesjonalnych programistów
Robert C. Martin
-
Wielkie umysły programowania. Jak myślą i pracu... Wielkie umysły programowania. Jak myślą i pracują twórcy najważniejszych języków
Federico Biancuzzi, Shane Warden
-
Czysta architektura. Struktura i design oprogra... Czysta architektura. Struktura i design oprogramowania. Przewodnik dla profesjonalistów
Robert C. Martin
-
Algorytmy Data Science. Siedmiodniowy przewodni... Algorytmy Data Science. Siedmiodniowy przewodnik. Wydanie II
David Natingga
-
Ciągłe dostarczanie oprogramowania w języku Jav... Ciągłe dostarczanie oprogramowania w języku Java. Najlepsze narzędzia i praktyki wdrażania kodu
Daniel Bryant, Abraham Marín-Pérez
Szczegóły książki
- ISBN Ebooka:
- 978-14-493-7932-2, 9781449379322
- Data wydania ebooka:
-
2009-10-02
Data wydania ebooka często jest dniem wprowadzenia tytułu do sprzedaży i może nie być równoznaczna z datą wydania książki papierowej. Dodatkowe informacje możesz znaleźć w darmowym fragmencie. Jeśli masz wątpliwości skontaktuj się z nami sklep@helion.pl.
- Język publikacji:
- angielski
- Rozmiar pliku ePub:
- 3.1MB
- Rozmiar pliku Mobi:
- 3.1MB
- Kategorie:
Programowanie » Python - Programowanie
Spis treści
- Learning Python
- Dedication
- A Note Regarding Supplemental Files
- Preface
- About This Fourth Edition
- Coverage for Both 3.0 and 2.6
- New Chapters
- Changes to Existing Material
- Specific Language Extensions in 2.6 and 3.0
- Specific Language Removals in 3.0
- About This Fourth Edition
- About The Third Edition
- The Third Editions Python Language Changes
- The Third Editions Python Training Changes
- The Third Editions Structural Changes
- The Third Editions Scope Changes
- About This Book
- This Books Prerequisites
- This Books Scope and Other Books
- This Books Style and Structure
- Book Updates
- About the Programs in This Book
- Using Code Examples
- Font Conventions
- Safari Books Online
- How to Contact Us
- Acknowledgments
- I. Getting Started
- 1. A Python Q&A Session
- Why Do People Use Python?
- Software Quality
- Developer Productivity
- Why Do People Use Python?
- Is Python a Scripting Language?
- OK, but Whats the Downside?
- Who Uses Python Today?
- What Can I Do with Python?
- Systems Programming
- GUIs
- Internet Scripting
- Component Integration
- Database Programming
- Rapid Prototyping
- Numeric and Scientific Programming
- Gaming, Images, Serial Ports, XML, Robots, and More
- 1. A Python Q&A Session
- How Is Python Supported?
- What Are Pythons Technical Strengths?
- Its Object-Oriented
- Its Free
- Its Portable
- Its Powerful
- Its Mixable
- Its Easy to Use
- Its Easy to Learn
- Its Named After Monty Python
- How Does Python Stack Up to Language X?
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- 2. How Python Runs Programs
- Introducing the Python Interpreter
- Program Execution
- The Programmers View
- Pythons View
- Byte code compilation
- The Python Virtual Machine (PVM)
- Performance implications
- Development implications
- Execution Model Variations
- Python Implementation Alternatives
- CPython
- Jython
- IronPython
- Python Implementation Alternatives
- Execution Optimization Tools
- The Psyco just-in-time compiler
- The Shedskin C++ translator
- Frozen Binaries
- Other Execution Options
- Future Possibilities?
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- 3. How You Run Programs
- The Interactive Prompt
- Running Code Interactively
- Why the Interactive Prompt?
- Experimenting
- Testing
- Using the Interactive Prompt
- Entering multiline statements
- The Interactive Prompt
- System Command Lines and Files
- A First Script
- Running Files with Command Lines
- Using Command Lines and Files
- Unix Executable Scripts (#!)
- Clicking File Icons
- Clicking Icons on Windows
- The input Trick
- Other Icon-Click Limitations
- Module Imports and Reloads
- The Grander Module Story: Attributes
- Modules and namespaces
- The Grander Module Story: Attributes
- import and reload Usage Notes
- Using exec to Run Module Files
- The IDLE User Interface
- IDLE Basics
- Using IDLE
- Advanced IDLE Tools
- Other IDEs
- Other Launch Options
- Embedding Calls
- Frozen Binary Executables
- Text Editor Launch Options
- Still Other Launch Options
- Future Possibilities?
- Which Option Should I Use?
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- Test Your Knowledge: Part I Exercises
- II. Types and Operations
- 4. Introducing Python Object Types
- Why Use Built-in Types?
- Pythons Core Data Types
- Why Use Built-in Types?
- Numbers
- Strings
- Sequence Operations
- Immutability
- Type-Specific Methods
- Getting Help
- Other Ways to Code Strings
- Pattern Matching
- 4. Introducing Python Object Types
- Lists
- Sequence Operations
- Type-Specific Operations
- Bounds Checking
- Nesting
- Comprehensions
- Dictionaries
- Mapping Operations
- Nesting Revisited
- Sorting Keys: for Loops
- Iteration and Optimization
- Missing Keys: if Tests
- Tuples
- Why Tuples?
- Files
- Other File-Like Tools
- Other Core Types
- How to Break Your Codes Flexibility
- User-Defined Classes
- And Everything Else
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- 5. Numeric Types
- Numeric Type Basics
- Numeric Literals
- Built-in Numeric Tools
- Python Expression Operators
- Mixed operators follow operator precedence
- Parentheses group subexpressions
- Mixed types are converted up
- Preview: Operator overloading and polymorphism
- Numeric Type Basics
- Numbers in Action
- Variables and Basic Expressions
- Numeric Display Formats
- Comparisons: Normal and Chained
- Division: Classic, Floor, and True
- Supporting either Python
- Floor versus truncation
- Why does truncation matter?
- Integer Precision
- Complex Numbers
- Hexadecimal, Octal, and Binary Notation
- Bitwise Operations
- Other Built-in Numeric Tools
- Other Numeric Types
- Decimal Type
- The basics
- Setting precision globally
- Decimal context manager
- Decimal Type
- Fraction Type
- The basics
- Numeric accuracy
- Conversions and mixed types
- Sets
- Set basics in Python 2.6
- Set literals in Python 3.0
- Immutable constraints and frozen sets
- Set comprehensions in Python 3.0
- Why sets?
- Booleans
- Numeric Extensions
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- 6. The Dynamic Typing Interlude
- The Case of the Missing Declaration Statements
- Variables, Objects, and References
- Types Live with Objects, Not Variables
- Objects Are Garbage-Collected
- The Case of the Missing Declaration Statements
- Shared References
- Shared References and In-Place Changes
- Shared References and Equality
- Dynamic Typing Is Everywhere
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- 7. Strings
- String Literals
- Single- and Double-Quoted Strings Are the Same
- Escape Sequences Represent Special Bytes
- Raw Strings Suppress Escapes
- Triple Quotes Code Multiline Block Strings
- String Literals
- Strings in Action
- Basic Operations
- Indexing and Slicing
- Extended slicing: the third limit and slice objects
- String Conversion Tools
- Character code conversions
- Changing Strings
- String Methods
- String Method Examples: Changing Strings
- String Method Examples: Parsing Text
- Other Common String Methods in Action
- The Original string Module (Gone in 3.0)
- String Formatting Expressions
- Advanced String Formatting Expressions
- Dictionary-Based String Formatting Expressions
- String Formatting Method Calls
- The Basics
- Adding Keys, Attributes, and Offsets
- Adding Specific Formatting
- Comparison to the % Formatting Expression
- Why the New Format Method?
- Extra features
- Explicit value references
- Method names and general arguments
- Possible future deprecation?
- General Type Categories
- Types Share Operation Sets by Categories
- Mutable Types Can Be Changed In-Place
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- 8. Lists and Dictionaries
- Lists
- Lists in Action
- Basic List Operations
- List Iteration and Comprehensions
- Indexing, Slicing, and Matrixes
- Changing Lists In-Place
- Index and slice assignments
- List method calls
- Other common list operations
- Dictionaries
- Dictionaries in Action
- Basic Dictionary Operations
- Changing Dictionaries In-Place
- More Dictionary Methods
- A Languages Table
- Dictionary Usage Notes
- Using dictionaries to simulate flexible lists
- Using dictionaries for sparse data structures
- Avoiding missing-key errors
- Using dictionaries as records
- Other Ways to Make Dictionaries
- Dictionary Changes in Python 3.0
- Dictionary comprehensions
- Dictionary views
- Dictionary views and sets
- Sorting dictionary keys
- Dictionary magnitude comparisons no longer work
- The has_key method is dead: long live in!
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- 9. Tuples, Files, and Everything Else
- Tuples
- Tuples in Action
- Tuple syntax peculiarities: Commas and parentheses
- Conversions, methods, and immutability
- Tuples in Action
- Why Lists and Tuples?
- Tuples
- Files
- Opening Files
- Using Files
- Files in Action
- Text and binary files in Python 3.0
- Storing and parsing Python objects in files
- Storing native Python objects with pickle
- Storing and parsing packed binary data in files
- File context managers
- Other File Tools
- Type Categories Revisited
- Object Flexibility
- References Versus Copies
- Comparisons, Equality, and Truth
- Python 3.0 Dictionary Comparisons
- The Meaning of True and False in Python
- The None object
- The bool type
- Pythons Type Hierarchies
- Type Objects
- Other Types in Python
- Built-in Type Gotchas
- Assignment Creates References, Not Copies
- Repetition Adds One Level Deep
- Beware of Cyclic Data Structures
- Immutable Types Cant Be Changed In-Place
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- Test Your Knowledge: Part II Exercises
- III. Statements and Syntax
- 10. Introducing Python Statements
- Python Program Structure Revisited
- Pythons Statements
- Python Program Structure Revisited
- A Tale of Two ifs
- What Python Adds
- What Python Removes
- Parentheses are optional
- End of line is end of statement
- End of indentation is end of block
- Why Indentation Syntax?
- A Few Special Cases
- Statement rule special cases
- Block rule special case
- 10. Introducing Python Statements
- A Quick Example: Interactive Loops
- A Simple Interactive Loop
- Doing Math on User Inputs
- Handling Errors by Testing Inputs
- Handling Errors with try Statements
- Nesting Code Three Levels Deep
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- 11. Assignments, Expressions, and Prints
- Assignment Statements
- Assignment Statement Forms
- Sequence Assignments
- Advanced sequence assignment patterns
- Extended Sequence Unpacking in Python 3.0
- Extended unpacking in action
- Boundary cases
- A useful convenience
- Application to for loops
- Assignment Statements
- Multiple-Target Assignments
- Multiple-target assignment and shared references
- Augmented Assignments
- Augmented assignment and shared references
- Variable Name Rules
- Naming conventions
- Names have no type, but objects do
- Expression Statements
- Expression Statements and In-Place Changes
- Print Operations
- The Python 3.0 print Function
- Call format
- The 3.0 print function in action
- The Python 3.0 print Function
- The Python 2.6 print Statement
- Statement forms
- The 2.6 print statement in action
- Print Stream Redirection
- The Python hello world program
- Manual stream redirection
- Automatic stream redirection
- Version-Neutral Printing
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- 12. if Tests and Syntax Rules
- if Statements
- General Format
- Basic Examples
- Multiway Branching
- if Statements
- Python Syntax Rules
- Block Delimiters: Indentation Rules
- Avoid mixing tabs and spaces: New error checking in 3.0
- Block Delimiters: Indentation Rules
- Statement Delimiters: Lines and Continuations
- A Few Special Cases
- Truth Tests
- The if/else Ternary Expression
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- 13. while and for Loops
- while Loops
- General Format
- Examples
- while Loops
- break, continue, pass, and the Loop else
- General Loop Format
- pass
- continue
- break
- Loop else
- More on the loop else
- for Loops
- General Format
- Examples
- Basic usage
- Other data types
- Tuple assignment in for loops
- Python 3.0 extended sequence assignment in for loops
- Nested for loops
- Loop Coding Techniques
- Counter Loops: while and range
- Nonexhaustive Traversals: range and Slices
- Changing Lists: range
- Parallel Traversals: zip and map
- map equivalence in Python 2.6
- Dictionary construction with zip
- Generating Both Offsets and Items: enumerate
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- 14. Iterations and Comprehensions, Part 1
- Iterators: A First Look
- The Iteration Protocol: File Iterators
- Manual Iteration: iter and next
- Other Built-in Type Iterators
- Iterators: A First Look
- List Comprehensions: A First Look
- List Comprehension Basics
- Using List Comprehensions on Files
- Extended List Comprehension Syntax
- Other Iteration Contexts
- New Iterables in Python 3.0
- The range Iterator
- The map, zip, and filter Iterators
- Multiple Versus Single Iterators
- Dictionary View Iterators
- Other Iterator Topics
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- 15. The Documentation Interlude
- Python Documentation Sources
- # Comments
- The dir Function
- Docstrings: __doc__
- User-defined docstrings
- Docstring standards
- Built-in docstrings
- PyDoc: The help Function
- PyDoc: HTML Reports
- The Standard Manual Set
- Web Resources
- Published Books
- Python Documentation Sources
- Common Coding Gotchas
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- Test Your Knowledge: Part III Exercises
- IV. Functions
- 16. Function Basics
- Why Use Functions?
- Coding Functions
- def Statements
- def Executes at Runtime
- A First Example: Definitions and Calls
- Definition
- Calls
- Polymorphism in Python
- 16. Function Basics
- A Second Example: Intersecting Sequences
- Definition
- Calls
- Polymorphism Revisited
- Local Variables
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- 17. Scopes
- Python Scope Basics
- Scope Rules
- Name Resolution: The LEGB Rule
- Scope Example
- The Built-in Scope
- Python Scope Basics
- The global Statement
- Minimize Global Variables
- Minimize Cross-File Changes
- Other Ways to Access Globals
- Scopes and Nested Functions
- Nested Scope Details
- Nested Scope Examples
- Factory functions
- Retaining enclosing scopes state with defaults
- Nested scopes and lambdas
- Scopes versus defaults with loop variables
- Arbitrary scope nesting
- The nonlocal Statement
- nonlocal Basics
- nonlocal in Action
- Using nonlocal for changes
- Boundary cases
- Why nonlocal?
- Shared state with globals
- State with classes (preview)
- State with function attributes
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- 18. Arguments
- Argument-Passing Basics
- Arguments and Shared References
- Avoiding Mutable Argument Changes
- Simulating Output Parameters
- Argument-Passing Basics
- Special Argument-Matching Modes
- The Basics
- Matching Syntax
- The Gritty Details
- Keyword and Default Examples
- Keywords
- Defaults
- Combining keywords and defaults
- Arbitrary Arguments Examples
- Collecting arguments
- Unpacking arguments
- Applying functions generically
- The defunct apply built-in (Python 2.6)
- Python 3.0 Keyword-Only Arguments
- Ordering rules
- Why keyword-only arguments?
- The min Wakeup Call!
- Full Credit
- Bonus Points
- The Punch Line...
- Generalized Set Functions
- Emulating the Python 3.0 print Function
- Using Keyword-Only Arguments
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- 19. Advanced Function Topics
- Function Design Concepts
- Recursive Functions
- Summation with Recursion
- Coding Alternatives
- Loop Statements Versus Recursion
- Handling Arbitrary Structures
- Function Objects: Attributes and Annotations
- Indirect Function Calls
- Function Introspection
- Function Attributes
- Function Annotations in 3.0
- Anonymous Functions: lambda
- lambda Basics
- Why Use lambda?
- How (Not) to Obfuscate Your Python Code
- Nested lambdas and Scopes
- Mapping Functions over Sequences: map
- Functional Programming Tools: filter and reduce
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- 20. Iterations and Comprehensions, Part 2
- List Comprehensions Revisited: Functional Tools
- List Comprehensions Versus map
- Adding Tests and Nested Loops: filter
- List Comprehensions and Matrixes
- Comprehending List Comprehensions
- List Comprehensions Revisited: Functional Tools
- Iterators Revisited: Generators
- Generator Functions: yield Versus return
- State suspension
- Iteration protocol integration
- Generator functions in action
- Extended generator function protocol: send versus next
- Generator Functions: yield Versus return
- Generator Expressions: Iterators Meet Comprehensions
- Generator Functions Versus Generator Expressions
- Generators Are Single-Iterator Objects
- Emulating zip and map with Iteration Tools
- Coding your own map(func, ...)
- Coding your own zip(...) and map(None, ...)
- Value Generation in Built-in Types and Classes
- 3.0 Comprehension Syntax Summary
- Comprehending Set and Dictionary Comprehensions
- Extended Comprehension Syntax for Sets and Dictionaries
- Timing Iteration Alternatives
- Timing Module
- Timing Script
- Timing Results
- Timing Module Alternatives
- Using keyword-only arguments in 3.0
- Other Suggestions
- Function Gotchas
- Local Names Are Detected Statically
- Defaults and Mutable Objects
- Functions Without returns
- Enclosing Scope Loop Variables
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- Test Your Knowledge: Part IV Exercises
- V. Modules
- 21. Modules: The Big Picture
- Why Use Modules?
- Python Program Architecture
- How to Structure a Program
- Imports and Attributes
- Standard Library Modules
- How Imports Work
- 1. Find It
- 2. Compile It (Maybe)
- 3. Run It
- 21. Modules: The Big Picture
- The Module Search Path
- Configuring the Search Path
- Search Path Variations
- The sys.path List
- Module File Selection
- Advanced Module Selection Concepts
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- 22. Module Coding Basics
- Module Creation
- Module Usage
- The import Statement
- The from Statement
- The from * Statement
- Imports Happen Only Once
- import and from Are Assignments
- Cross-File Name Changes
- import and from Equivalence
- Potential Pitfalls of the from Statement
- When import is required
- Module Namespaces
- Files Generate Namespaces
- Attribute Name Qualification
- Imports Versus Scopes
- Namespace Nesting
- Reloading Modules
- reload Basics
- reload Example
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- 23. Module Packages
- Package Import Basics
- Packages and Search Path Settings
- Package __init__.py Files
- Package Import Basics
- Package Import Example
- from Versus import with Packages
- Why Use Package Imports?
- A Tale of Three Systems
- Package Relative Imports
- Changes in Python 3.0
- Relative Import Basics
- Why Relative Imports?
- The relative imports solution in 3.0
- Relative imports versus absolute package paths
- The Scope of Relative Imports
- Module Lookup Rules Summary
- Relative Imports in Action
- Imports outside packages
- Imports within packages
- Imports are still relative to the CWD
- Selecting modules with relative and absolute imports
- Imports are still relative to the CWD (again)
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- 24. Advanced Module Topics
- Data Hiding in Modules
- Minimizing from * Damage: _X and __all__
- Data Hiding in Modules
- Enabling Future Language Features
- Mixed Usage Modes: __name__ and __main__
- Unit Tests with __name__
- Using Command-Line Arguments with __name__
- Changing the Module Search Path
- The as Extension for import and from
- Modules Are Objects: Metaprograms
- Importing Modules by Name String
- Transitive Module Reloads
- Module Design Concepts
- Module Gotchas
- Statement Order Matters in Top-Level Code
- from Copies Names but Doesnt Link
- from * Can Obscure the Meaning of Variables
- reload May Not Impact from Imports
- reload, from, and Interactive Testing
- Recursive from Imports May Not Work
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- Test Your Knowledge: Part V Exercises
- VI. Classes and OOP
- 25. OOP: The Big Picture
- Why Use Classes?
- OOP from 30,000 Feet
- Attribute Inheritance Search
- Classes and Instances
- Class Method Calls
- Coding Class Trees
- OOP Is About Code Reuse
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- 25. OOP: The Big Picture
- 26. Class Coding Basics
- Classes Generate Multiple Instance Objects
- Class Objects Provide Default Behavior
- Instance Objects Are Concrete Items
- A First Example
- Classes Generate Multiple Instance Objects
- Classes Are Customized by Inheritance
- A Second Example
- Classes Are Attributes in Modules
- Classes Can Intercept Python Operators
- A Third Example
- Why Use Operator Overloading?
- The Worlds Simplest Python Class
- Classes Versus Dictionaries
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- 27. A More Realistic Example
- Step 1: Making Instances
- Coding Constructors
- Testing As You Go
- Using Code Two Ways
- Step 1: Making Instances
- Step 2: Adding Behavior Methods
- Coding Methods
- Step 3: Operator Overloading
- Providing Print Displays
- Step 4: Customizing Behavior by Subclassing
- Coding Subclasses
- Augmenting Methods: The Bad Way
- Augmenting Methods: The Good Way
- Polymorphism in Action
- Inherit, Customize, and Extend
- OOP: The Big Idea
- Step 5: Customizing Constructors, Too
- OOP Is Simpler Than You May Think
- Other Ways to Combine Classes
- Step 6: Using Introspection Tools
- Special Class Attributes
- A Generic Display Tool
- Instance Versus Class Attributes
- Name Considerations in Tool Classes
- Our Classes Final Form
- Step 7 (Final): Storing Objects in a Database
- Pickles and Shelves
- Storing Objects on a Shelve Database
- Exploring Shelves Interactively
- Updating Objects on a Shelve
- Future Directions
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- 28. Class Coding Details
- The class Statement
- General Form
- Example
- The class Statement
- Methods
- Method Example
- Calling Superclass Constructors
- Other Method Call Possibilities
- Inheritance
- Attribute Tree Construction
- Specializing Inherited Methods
- Class Interface Techniques
- Abstract Superclasses
- Python 2.6 and 3.0 Abstract Superclasses
- Namespaces: The Whole Story
- Simple Names: Global Unless Assigned
- Attribute Names: Object Namespaces
- The Zen of Python Namespaces: Assignments Classify Names
- Namespace Dictionaries
- Namespace Links
- Documentation Strings Revisited
- Classes Versus Modules
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- 29. Operator Overloading
- The Basics
- Constructors and Expressions: __init__ and __sub__
- Common Operator Overloading Methods
- The Basics
- Indexing and Slicing: __getitem__ and __setitem__
- Intercepting Slices
- Index Iteration: __getitem__
- Iterator Objects: __iter__ and __next__
- User-Defined Iterators
- Multiple Iterators on One Object
- Membership: __contains__, __iter__, and __getitem__
- Attribute Reference: __getattr__ and __setattr__
- Other Attribute Management Tools
- Emulating Privacy for Instance Attributes: Part 1
- String Representation: __repr__ and __str__
- Right-Side and In-Place Addition: __radd__ and __iadd__
- In-Place Addition
- Call Expressions: __call__
- Function Interfaces and Callback-Based Code
- Comparisons: __lt__, __gt__, and Others
- The 2.6 __cmp__ Method (Removed in 3.0)
- Boolean Tests: __bool__ and __len__
- Object Destruction: __del__
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- 30. Designing with Classes
- Python and OOP
- Overloading by Call Signatures (or Not)
- Python and OOP
- OOP and Inheritance: Is-a Relationships
- OOP and Composition: Has-a Relationships
- Stream Processors Revisited
- OOP and Delegation: Wrapper Objects
- Pseudoprivate Class Attributes
- Name Mangling Overview
- Why Use Pseudoprivate Attributes?
- Methods Are Objects: Bound or Unbound
- Unbound Methods are Functions in 3.0
- Bound Methods and Other Callable Objects
- Multiple Inheritance: Mix-in Classes
- Coding Mix-in Display Classes
- Listing instance attributes with __dict__
- Listing inherited attributes with dir
- Listing attributes per object in class trees
- Coding Mix-in Display Classes
- Classes Are Objects: Generic Object Factories
- Why Factories?
- Other Design-Related Topics
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- 31. Advanced Class Topics
- Extending Built-in Types
- Extending Types by Embedding
- Extending Types by Subclassing
- Extending Built-in Types
- The New-Style Class Model
- New-Style Class Changes
- Type Model Changes
- Implications for type testing
- All objects derive from object
- Type Model Changes
- Diamond Inheritance Change
- Diamond inheritance example
- Explicit conflict resolution
- Scope of search order change
- New-Style Class Extensions
- Instance Slots
- Slots and generic code
- Multiple __slot__ lists in superclasses
- Instance Slots
- Class Properties
- __getattribute__ and Descriptors
- Metaclasses
- Static and Class Methods
- Why the Special Methods?
- Static Methods in 2.6 and 3.0
- Static Method Alternatives
- Using Static and Class Methods
- Counting Instances with Static Methods
- Counting Instances with Class Methods
- Counting instances per class with class methods
- Decorators and Metaclasses: Part 1
- Function Decorator Basics
- A First Function Decorator Example
- Class Decorators and Metaclasses
- For More Details
- Class Gotchas
- Changing Class Attributes Can Have Side Effects
- Changing Mutable Class Attributes Can Have Side Effects, Too
- Multiple Inheritance: Order Matters
- Methods, Classes, and Nested Scopes
- Delegation-Based Classes in 3.0: __getattr__ and built-ins
- Overwrapping-itis
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- Test Your Knowledge: Part VI Exercises
- VII. Exceptions and Tools
- 32. Exception Basics
- Why Use Exceptions?
- Exception Roles
- Why Use Exceptions?
- Exceptions: The Short Story
- Default Exception Handler
- Catching Exceptions
- Raising Exceptions
- User-Defined Exceptions
- Termination Actions
- 32. Exception Basics
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- 33. Exception Coding Details
- The try/except/else Statement
- try Statement Clauses
- The try else Clause
- Example: Default Behavior
- Example: Catching Built-in Exceptions
- The try/except/else Statement
- The try/finally Statement
- Example: Coding Termination Actions with try/finally
- Unified try/except/finally
- Unified try Statement Syntax
- Combining finally and except by Nesting
- Unified try Example
- The raise Statement
- Propagating Exceptions with raise
- Python 3.0 Exception Chaining: raise from
- The assert Statement
- Example: Trapping Constraints (but Not Errors!)
- with/as Context Managers
- Basic Usage
- The Context Management Protocol
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- 34. Exception Objects
- Exceptions: Back to the Future
- String Exceptions Are Right Out!
- Class-Based Exceptions
- Coding Exceptions Classes
- Exceptions: Back to the Future
- Why Exception Hierarchies?
- Built-in Exception Classes
- Built-in Exception Categories
- Default Printing and State
- Custom Print Displays
- Custom Data and Behavior
- Providing Exception Details
- Providing Exception Methods
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- 35. Designing with Exceptions
- Nesting Exception Handlers
- Example: Control-Flow Nesting
- Example: Syntactic Nesting
- Nesting Exception Handlers
- Exception Idioms
- Exceptions Arent Always Errors
- Functions Can Signal Conditions with raise
- Closing Files and Server Connections
- Debugging with Outer try Statements
- Running In-Process Tests
- More on sys.exc_info
- Exception Design Tips and Gotchas
- What Should Be Wrapped
- Catching Too Much: Avoid Empty except and Exception
- Catching Too Little: Use Class-Based Categories
- Core Language Summary
- The Python Toolset
- Development Tools for Larger Projects
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- Test Your Knowledge: Part VII Exercises
- VIII. Advanced Topics
- 36. Unicode and Byte Strings
- String Changes in 3.0
- String Basics
- Character Encoding Schemes
- Pythons String Types
- Text and Binary Files
- Python 3.0 Strings in Action
- Literals and Basic Properties
- Conversions
- 36. Unicode and Byte Strings
- Coding Unicode Strings
- Coding ASCII Text
- Coding Non-ASCII Text
- Encoding and Decoding Non-ASCII text
- Other Unicode Coding Techniques
- Converting Encodings
- Coding Unicode Strings in Python 2.6
- Source File Character Set Encoding Declarations
- Using 3.0 Bytes Objects
- Method Calls
- Sequence Operations
- Other Ways to Make bytes Objects
- Mixing String Types
- Using 3.0 (and 2.6) bytearray Objects
- Using Text and Binary Files
- Text File Basics
- Text and Binary Modes in 3.0
- Type and Content Mismatches
- Using Unicode Files
- Reading and Writing Unicode in 3.0
- Manual encoding
- File output encoding
- File input decoding
- Decoding mismatches
- Reading and Writing Unicode in 3.0
- Handling the BOM in 3.0
- Unicode Files in 2.6
- Other String Tool Changes in 3.0
- The re Pattern Matching Module
- The struct Binary Data Module
- The pickle Object Serialization Module
- XML Parsing Tools
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- 37. Managed Attributes
- Why Manage Attributes?
- Inserting Code to Run on Attribute Access
- Why Manage Attributes?
- Properties
- The Basics
- A First Example
- Computed Attributes
- Coding Properties with Decorators
- Descriptors
- The Basics
- Descriptor method arguments
- Read-only descriptors
- The Basics
- A First Example
- Computed Attributes
- Using State Information in Descriptors
- How Properties and Descriptors Relate
- __getattr__ and __getattribute__
- The Basics
- Avoiding loops in attribute interception methods
- The Basics
- A First Example
- Computed Attributes
- __getattr__ and __getattribute__ Compared
- Management Techniques Compared
- Intercepting Built-in Operation Attributes
- Delegation-Based Managers Revisited
- Example: Attribute Validations
- Using Properties to Validate
- Self-test code
- Using Properties to Validate
- Using Descriptors to Validate
- Using __getattr__ to Validate
- Using __getattribute__ to Validate
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- 38. Decorators
- Whats a Decorator?
- Managing Calls and Instances
- Managing Functions and Classes
- Using and Defining Decorators
- Why Decorators?
- Whats a Decorator?
- The Basics
- Function Decorators
- Usage
- Implementation
- Supporting method decoration
- Function Decorators
- Class Decorators
- Usage
- Implementation
- Supporting multiple instances
- Decorator Nesting
- Decorator Arguments
- Decorators Manage Functions and Classes, Too
- Coding Function Decorators
- Tracing Calls
- State Information Retention Options
- Class instance attributes
- Enclosing scopes and globals
- Enclosing scopes and nonlocals
- Function attributes
- Class Blunders I: Decorating Class Methods
- Using nested functions to decorate methods
- Using descriptors to decorate methods
- Timing Calls
- Adding Decorator Arguments
- Coding Class Decorators
- Singleton Classes
- Tracing Object Interfaces
- Class Blunders II: Retaining Multiple Instances
- Decorators Versus Manager Functions
- Why Decorators? (Revisited)
- Managing Functions and Classes Directly
- Example: Private and Public Attributes
- Implementing Private Attributes
- Implementation Details I
- Inheritance versus delegation
- Decorator arguments
- State retention and enclosing scopes
- Using __dict__ and __slots__
- Generalizing for Public Declarations, Too
- Implementation Details II
- Using __X pseudoprivate names
- Breaking privacy
- Decorator tradeoffs
- Open Issues
- Caveat: operator overloading methods fail to delegate under 3.0
- Implementation alternatives: __getattribute__ inserts, call stack inspection
- Python Isnt About Control
- Example: Validating Function Arguments
- The Goal
- A Basic Range-Testing Decorator for Positional Arguments
- Generalizing for Keywords and Defaults, Too
- Implementation Details
- Function introspection
- Argument assumptions
- Matching algorithm
- Open Issues
- Decorator Arguments Versus Function Annotations
- Other Applications: Type Testing (If You Insist!)
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- 39. Metaclasses
- To Metaclass or Not to Metaclass
- Increasing Levels of Magic
- The Downside of Helper Functions
- Metaclasses Versus Class Decorators: Round 1
- To Metaclass or Not to Metaclass
- The Metaclass Model
- Classes Are Instances of type
- Metaclasses Are Subclasses of Type
- Class Statement Protocol
- Declaring Metaclasses
- Coding Metaclasses
- A Basic Metaclass
- Customizing Construction and Initialization
- Other Metaclass Coding Techniques
- Using simple factory functions
- Overloading class creation calls with metaclasses
- Overloading class creation calls with normal classes
- Instances Versus Inheritance
- Example: Adding Methods to Classes
- Manual Augmentation
- Metaclass-Based Augmentation
- Metaclasses Versus Class Decorators: Round 2
- Decorator-based augmentation
- Managing instances instead of classes
- Example: Applying Decorators to Methods
- Tracing with Decoration Manually
- Tracing with Metaclasses and Decorators
- Applying Any Decorator to Methods
- Metaclasses Versus Class Decorators: Round 3
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- IX. Appendixes
- A. Installation and Configuration
- Installing the Python Interpreter
- Is Python Already Present?
- Where to Get Python
- Installation Steps
- Installing the Python Interpreter
- Configuring Python
- Python Environment Variables
- How to Set Configuration Options
- Unix/Linux shell variables
- DOS variables (Windows)
- Windows environment variable GUI
- Windows registry
- Path files
- Python Command-Line Options
- A. Installation and Configuration
- For More Help
- B. Solutions to End-of-Part Exercises
- Part I, Getting Started
- Part II, Types and Operations
- Part III, Statements and Syntax
- Part IV, Functions
- Part V, Modules
- Part VI, Classes and OOP
- Part VII, Exceptions and Tools
- Index
- About the Author
- Colophon
- Copyright
Dzieki opcji "Druk na żądanie" do sprzedaży wracają tytuły Grupy Helion, które cieszyły sie dużym zainteresowaniem, a których nakład został wyprzedany.
Dla naszych Czytelników wydrukowaliśmy dodatkową pulę egzemplarzy w technice druku cyfrowego.
Co powinieneś wiedzieć o usłudze "Druk na żądanie":
- usługa obejmuje tylko widoczną poniżej listę tytułów, którą na bieżąco aktualizujemy;
- cena książki może być wyższa od początkowej ceny detalicznej, co jest spowodowane kosztami druku cyfrowego (wyższymi niż koszty tradycyjnego druku offsetowego). Obowiązująca cena jest zawsze podawana na stronie WWW książki;
- zawartość książki wraz z dodatkami (płyta CD, DVD) odpowiada jej pierwotnemu wydaniu i jest w pełni komplementarna;
- usługa nie obejmuje książek w kolorze.
W przypadku usługi "Druk na żądanie" termin dostarczenia przesyłki może obejmować także czas potrzebny na dodruk (do 10 dni roboczych)
Masz pytanie o konkretny tytuł? Napisz do nas: sklep[at]helion.pl.


Oceny i opinie klientów (0)