Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

decorator patter

#decorator pattern uses a decorator that adds a bahavior to an existing function or class  
# e.g. here is aDecorator that is a wrapper function 
def aDecorator(func):     #func is the wrapped function
   def wrapper(*args, **kwargs):
      ret = func(*args, **kwargs)  #get reault of wrapped function
      return f' Decorator has converted result to upper-case: {ret.upper()} '
   return wrapper          #wrapper contains the decoration and result of wrapped function 

@aDecorator                # aDecorator is the wrapper function
def exampleFunction():
   return "basic output"   #lower-case string

print(exampleFunction())   #addDecoration adds note and converts to Upper-case

#Output:
#  Decorator has converted result to upper-case: BASIC OUTPUT 
Comment

PREVIOUS NEXT
Code Example
Python :: how to run a seaborn plot on pycharm 
Python :: print out python 
Python :: django router multiple pk 
Python :: add percentage sign to string python 
Python :: programme phyton pour realiser un programme qui transforme une image en niveau de gris 
Python :: back of list 
Python :: logistic distribution location and scale parameters 
Python :: Python - Cómo cruda la cuerda 
Python :: how to open camre aopencv 
Python :: dice rolling app in python 
Python :: find las element of array python 
Python :: create matrix with complex python 
Python :: discord.py custom status 
Python :: make a function that accepts any nuber of arguments python 
Python :: Kinesis Client get_records response json 
Python :: permcheck codility python 
Python :: create model object from dictionary 
Python :: pyglet on close 
Python :: django route accept params with character 
Python :: first n lis tpython 
Python :: dataframe passed by reference or value 
Python :: improt kmean 
Python :: comprehensions 
Python :: missing number 
Python :: django graphene without model 
Python :: rolling call on one column and groupby second pandas 
Python :: stop animation matplotlib 
Python :: pafy python documentation 
Python :: select features and label from df 
Python :: Higher-order functions and operations on callable objects in python 
ADD CONTENT
Topic
Content
Source link
Name
9+1 =