File tree Expand file tree Collapse file tree 1 file changed +13
-13
lines changed Expand file tree Collapse file tree 1 file changed +13
-13
lines changed Original file line number Diff line number Diff line change 1
- ## Advanced python decorator function
1
+ ## Advanced Python Decorator Functions
2
2
3
3
class User :
4
- def __init__ (self , name ) -> None :
4
+ def __init__ (self , name ):
5
5
self .name = name
6
6
self .is_logged_in = False
7
-
8
- def is_authenticated_decorator (function ):
9
- def wrapper (* args , ** kwargs ):
7
+
8
+ def is_authenticated_decorator (function ):
9
+ def wrapper (* args , ** kwargs ):
10
10
if args [0 ].is_logged_in == True :
11
- function ()
12
- return wrapper ()
13
-
11
+ function (args [ 0 ] )
12
+ return wrapper
13
+
14
14
@is_authenticated_decorator
15
15
def create_blog_post (user ):
16
- print (f"This is { user .name } 's ne blog post" )
17
-
18
-
19
- new_user = User ( "albin" )
20
- new_user . create_blog_post (new_user )
16
+ print (f"This is { user .name } 's new blog post. " )
17
+
18
+ new_user = User ( "angela" )
19
+ new_user . is_logged_in = True
20
+ create_blog_post (new_user )
You can’t perform that action at this time.
0 commit comments