diff --git a/Python-Decorator-Arguments/decorator-finish.py b/Python-Decorator-Arguments/decorator-finish.py new file mode 100644 index 0000000..4f1ce4e --- /dev/null +++ b/Python-Decorator-Arguments/decorator-finish.py @@ -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) diff --git a/Python-Decorator-Arguments/decorator-start.py b/Python-Decorator-Arguments/decorator-start.py new file mode 100644 index 0000000..271a6d7 --- /dev/null +++ b/Python-Decorator-Arguments/decorator-start.py @@ -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) diff --git a/Python-Decorator-Arguments/flask-hello.py b/Python-Decorator-Arguments/flask-hello.py new file mode 100644 index 0000000..e961d8c --- /dev/null +++ b/Python-Decorator-Arguments/flask-hello.py @@ -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()