decorator - Py i
This commit is contained in:
		
							parent
							
								
									fc05b23930
								
							
						
					
					
						commit
						228eef0258
					
				|  | @ -0,0 +1,11 @@ | ||||||
|  | def decorator(func): | ||||||
|  |     def wrapper(): | ||||||
|  |         print("Something is happening before the function is called.") | ||||||
|  |         func() | ||||||
|  |         print("Something is happening after the function is called.") | ||||||
|  |     return wrapper | ||||||
|  | 
 | ||||||
|  | def say_whee(): | ||||||
|  |     print("Whee!") | ||||||
|  | 
 | ||||||
|  | say_whee = decorator(say_whee) | ||||||
|  | @ -1,11 +1,11 @@ | ||||||
| def parent(): | def parent(num): | ||||||
|     print("Printing from parent()") |  | ||||||
| 
 |  | ||||||
|     def first_child(): |     def first_child(): | ||||||
|         print("Printing from first_child()") |         return "Hi, I'm Elias" | ||||||
| 
 | 
 | ||||||
|     def second_child(): |     def second_child(): | ||||||
|         print("Printing from second_child()") |         return "Call me Ester" | ||||||
| 
 | 
 | ||||||
|     second_child() |     if num == 1: | ||||||
|     first_child() |         return first_child | ||||||
|  |     else: | ||||||
|  |         return second_child | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue