Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

class decor python

# class decorator 
import random

# changes the properties of a function to a class instance
class Eliphant:
    def __init__(self,funct):
        self._funct = funct
        #all return values are storredin momory
        self._memory = []

    def __call__(self):
        returnvalue = self._funct()
        self._memory.append(returnvalue)
        return returnvalue

    def memory(self):
        return self._memory


@Eliphant

def random_odd():
    return random.choice([1,3,5,7,9])
print(random_odd())
print(random_odd.memory())
print(random_odd())
print(random_odd.memory())
 
PREVIOUS NEXT
Tagged: #class #decor #python
ADD COMMENT
Topic
Name
2+7 =