FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-patterns/decorator.py at master · rootlessweed/python-patterns · GitHub
rootlessweed
/
python-patterns
Public
forked from
faif/python-patterns
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
python-patterns
/
decorator.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
28 lines (22 loc) · 745 Bytes
Breadcrumbs
python-patterns
/
decorator.py
Copy path
File metadata and controls
28 lines (22 loc) · 745 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
'''https://docs.python.org/2/library/functools.html#functools.wraps'''
'''https://stackoverflow.com/questions/739654/how-can-i-make-a-chain-of-function-decorators-in-python/739665#739665'''
from
functools
import
wraps
def
makebold
(
fn
):
@
wraps
(
fn
)
def
wrapped
():
return
"<b>"
+
fn
()
+
"</b>"
return
wrapped
def
makeitalic
(
fn
):
@
wraps
(
fn
)
def
wrapped
():
return
"<i>"
+
fn
()
+
"</i>"
return
wrapped
@
makebold
@
makeitalic
def
hello
():
'''a decorated hello world'''
return
"hello world"
if
__name__
==
'__main__'
:
print
(
'result:{} name:{} doc:{}'
.
format
(
hello
(),
hello
.
__name__
,
hello
.
__doc__
))
### OUTPUT ###
# result:<b><i>hello world</i></b> name:hello doc:a decorated hello world
Back
|
FazBrowse Home
|
New Git URL