12.07.2015 Views

Is Python a

Is Python a

Is Python a

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

24. Class Coding Details . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 481The class Statement 481General Form 481Example 482Methods 484Example 485Calling Superclass Constructors 486Other Method Call Possibilities 486Inheritance 486Attribute Tree Construction 487Specializing Inherited Methods 488Class Interface Techniques 489Abstract Superclasses 490Operator Overloading 491Common Operator Overloading Methods 492_ _getitem_ _ Intercepts Index References 493_ _getitem_ _ and _ _iter_ _ Implement Iteration 493User-Defined Iterators 494Multiple iterators on one object 496_ _getattr_ _ and _ _setattr_ _ Catch Attribute References 498Emulating Privacy for Instance Attributes 499_ _repr_ _ and _ _str_ _ Return String Representations 500_ _radd_ _ Handles Right-Side Addition 502_ _call_ _ Intercepts Calls 502Function Interfaces and Callback-Based Code 503_ _del_ _ <strong>Is</strong> a Destructor 505Namespaces: The Whole Story 506Simple Names: Global Unless Assigned 506Attribute Names: Object Namespaces 506The “Zen” of <strong>Python</strong> Namespaces: Assignments Classify Names 506Namespace Dictionaries 508Namespace Links 511A More Realistic Example 512Chapter Summary 515Brain Builder 516Chapter Quiz 516Quiz Answers 516xxiv | Table of Contents

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!