Potentially useful code snippets
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

38 lines
749 B

from random import randint
#this is the decorator
def decor(func): #takes a function as an argument
def x(z): # z = arguments passed from function that was decorated
print('now with decoration') #extra shit from the decorator
func(z) #run that function
return x #return the decorator function
@decor #invoke the decorator
def z(number):
print(number)
z(3)
#this is the functional equivalent
def decor2(func):
def x(z):
print('also with decoration')
func(z)
return x
def q(number):
print(number)
zz=decor2(q)
zz(3)
##another example
@decor
def othershite(thing):
x=randint(1,100)
print(f'here is some other shite and a random number({x}) plus {thing}')
othershite('piztak')