File tree Expand file tree Collapse file tree 3 files changed +42
-0
lines changed Expand file tree Collapse file tree 3 files changed +42
-0
lines changed Original file line number Diff line number Diff line change
1
+ ##Illustrating the decorators concept
2
+ # Example 1
3
+ from datetime import datetime
4
+
5
+ def decorator_func (func ):
6
+ def wrapper (* args , ** kwargs ):
7
+ if 7 <= datetime .now ().hour < 16 :
8
+ func (* args , ** kwargs )
9
+ else :
10
+ pass # Hush, the neighbors are asleep
11
+ return wrapper
Original file line number Diff line number Diff line change
1
+ ##Illustrating the decorator call concept
2
+ # Example 1
3
+ from decorator import decorator_func
4
+ from datetime import datetime
5
+
6
+ def dec_call ():
7
+ print ("This is implemented using the bald representation for decorators." )
8
+
9
+ def non_decorator_call ():
10
+ print ("This is called without using a decorator." )
11
+
12
+ @decorator_func
13
+ def dec_call_2 ():
14
+ print ("This is implemented using syntactic sugar representation for decorators." )
15
+
16
+ print ("Time now = " + str (datetime .now ().hour ))
17
+ dec_call = decorator_func (dec_call )
18
+
19
+
20
+ dec_call ()
21
+ non_decorator_call ()
22
+ dec_call_2 ()
Original file line number Diff line number Diff line change
1
+ ##Illustrating the decorator call with arguments concept
2
+ # Example 1
3
+ from decorator import decorator_func
4
+
5
+ @decorator_func
6
+ def dec_call3 (name ):
7
+ print (f"Hi this is the diff file call by { name } " )
8
+
9
+ dec_call3 ("Abhiram" )
You can’t perform that action at this time.
0 commit comments