uio-bmi/programming_session_decorators

Name: programming_session_decorators

Owner: Biomedical Informatics Research Group (BMI)

Description: Exercices/examples for programming session on decorators

Created: 2017-11-14 15:10:55.0

Updated: 2017-11-15 10:11:07.0

Pushed: 2017-11-15 10:16:08.0

Homepage: null

Size: 11

Language: Python

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Programming session on decorators

Some examples can be found here.

Example decorators that can be made

@print_on_call Prints something every time the method is being called.

@print_arguments_on_call Prints string of arguments every time the method is being called.

@assert_output_is_int Checks the output of the method. Asserts that the output is int (isinstance(output, int))

@assert_output_is(type) Asserts that the output is of the given type.

@log(file_name) Logs the method name and input to file.

@takes(type1, type2, …) Asserts that all arguments are of the given types

memoize Memoizes the output of the function. Using the arguments as unique key.

@count_calls Counts have many time each method is being called. Prints or logs the number of times.

….


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.