Skip to content

Commit bbc90fa

Browse files
committed
Decorator Args Tutorial
1 parent dc29fb6 commit bbc90fa

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

Diff for: Python-Decorator-Arguments/decorator-finish.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Decorators
2+
3+
4+
def prefix_decorator(prefix):
5+
def decorator_function(original_function):
6+
def wrapper_function(*args, **kwargs):
7+
print(prefix, 'Executed Before', original_function.__name__)
8+
result = original_function(*args, **kwargs)
9+
print(prefix, 'Executed After', original_function.__name__, '\n')
10+
return result
11+
return wrapper_function
12+
return decorator_function
13+
14+
15+
@prefix_decorator('LOG:')
16+
def display_info(name, age):
17+
print('display_info ran with arguments ({}, {})'.format(name, age))
18+
19+
20+
display_info('John', 25)
21+
display_info('Travis', 30)

Diff for: Python-Decorator-Arguments/decorator-start.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Decorators
2+
3+
4+
def decorator_function(original_function):
5+
def wrapper_function(*args, **kwargs):
6+
print('Executed Before', original_function.__name__)
7+
result = original_function(*args, **kwargs)
8+
print('Executed After', original_function.__name__, '\n')
9+
return result
10+
return wrapper_function
11+
12+
13+
@decorator_function
14+
def display_info(name, age):
15+
print('display_info ran with arguments ({}, {})'.format(name, age))
16+
17+
18+
display_info('John', 25)
19+
display_info('Travis', 30)

Diff for: Python-Decorator-Arguments/flask-hello.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
from flask import Flask
3+
app = Flask(__name__)
4+
5+
6+
@app.route("/")
7+
def hello():
8+
return "Hello World!"
9+
10+
11+
@app.route("/about")
12+
def about():
13+
return "About Page"
14+
15+
if __name__ == "__main__":
16+
app.run()

0 commit comments

Comments
 (0)