Navigation
index
next
|
Objects and classes in Python tutorial
»
Objects and classes in Python
ΒΆ
Contents:
Decorators
The decorator syntax
Bound methods
staticmethod()
classmethod()
The
call()
decorator
Nesting decorators
Class decorators before Python 2.6
Constructing classes
The empty class
dict_from_class()
The __dict__ of the empty class
Is the doc-string part of the body?
Definition of
dict_from_class()
property_from_class()
About properties
Definition of
property_from_class()
Using
property_from_class()
Unwanted keys
Deconstructing classes
type(name, bases, dict)
Constructing the empty class
Constructing any class
Specifying __doc__, __name__ and __module__
Subclassing
int
Mutable and immutable types
Enumerated integers and named tuples
The
bool
type
Emulating
bool
- the easy part
Emulating
bool
- what goes wrong
Emulating
bool
- using __new__
Understanding
int.__new__
Subclassing
tuple
The desired properties of Point
Answer
What happens when you call a class?
Creation and initialisation
The default __new__
Summary
Metaclass
Every object has a type
The metaclass of an object
A trivial non-type metaclass
A non-trivial example
What’s the point?
The
__metaclass__
attribute
Automatic subclassing of object
Review of type(name, bases, body) and class statement
The basic principle of the __metaclass__
A very silly example
A less silly example
A __metaclass__ gotcha
A decorator example
Decorators versus __metaclass__
Bunch using decorators
Bunch using __metaclass__
How __metaclass__ works
Discussion
JavaScript objects
Like Python classes
Custom item methods
On metaclass
Never instantiated
Conclusion
Exercise: A line from a file
Exercise: Property from class decorator
Exercise: Named integers
Exercise: Subset of a set
Exercise: Class to and from class data
Exercise: Your own class to class decorator
Search Page
Next topic
Decorators
This Page
Show Source
Quick search
Enter search terms or a module, class or function name.
Navigation
index
next
|
Objects and classes in Python tutorial
»