File: class/Workbook/Examples/Lecture7/overloads.py

class indexer:
    def __getitem__(self, index):
        return index ** 2

class empty:
    def __getattr__(self, attrname):
        return attrname + ' not supported!'

class adder:
    def __init__(self, value=0):
        self.data = value              # init data
    def __add__(self, other):
        self.data = self.data + other  # add other
    def __repr__(self):
        return `self.data`             # to string



[Home page] Books Code Blog Python Author Train Find ©M.Lutz