def call (self): # implement the () operators, i.e. using an object as a function
getattr
Called when a method or member variable is selected on an object with the ‘.’ operator. With this function it is possible to create methods which are not defined as normal member functions
def getattr(self, name): if name == ‘add’: return mySpecialAddFunction
def init(self): # Called when an object is created
def del(self): # Called when an object is destroyed
def str(self): # Defines what the str() function returns
| Functions for defining the [] operator |
|---|
| The lenght operator: |
| def len(self): # Should return the length of the container. This value is returned when len() is called on the object. |
Funcitons for making an object iterable:
iter(self) # A class which implements this function it Iterable. It must return an Iterator.
next(self) # A class which implements this function is an Iterator. It must return the ‘next’ element from an Iterable object.
rmul
zie ook: https://blog.cambridgespark.com/magic-methods-a8d93dc55012 https://docs.python.org/3/reference/datamodel.html#special-method-names
dict # This is the dictionary containing the modules symbol table
Descriptor protocol:
get
set
delete
set_name