Skip to content

Commit

Permalink
Decorator Args Tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
CoreyMSchafer committed Mar 27, 2017
1 parent dc29fb6 commit bbc90fa
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Python-Decorator-Arguments/decorator-finish.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Decorators


def prefix_decorator(prefix):
def decorator_function(original_function):
def wrapper_function(*args, **kwargs):
print(prefix, 'Executed Before', original_function.__name__)
result = original_function(*args, **kwargs)
print(prefix, 'Executed After', original_function.__name__, '\n')
return result
return wrapper_function
return decorator_function


@prefix_decorator('LOG:')
def display_info(name, age):
print('display_info ran with arguments ({}, {})'.format(name, age))


display_info('John', 25)
display_info('Travis', 30)
19 changes: 19 additions & 0 deletions Python-Decorator-Arguments/decorator-start.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Decorators


def decorator_function(original_function):
def wrapper_function(*args, **kwargs):
print('Executed Before', original_function.__name__)
result = original_function(*args, **kwargs)
print('Executed After', original_function.__name__, '\n')
return result
return wrapper_function


@decorator_function
def display_info(name, age):
print('display_info ran with arguments ({}, {})'.format(name, age))


display_info('John', 25)
display_info('Travis', 30)
16 changes: 16 additions & 0 deletions Python-Decorator-Arguments/flask-hello.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

from flask import Flask
app = Flask(__name__)


@app.route("/")
def hello():
return "Hello World!"


@app.route("/about")
def about():
return "About Page"

if __name__ == "__main__":
app.run()

0 comments on commit bbc90fa

Please sign in to comment.