Skip to content

Instantly share code, notes, and snippets.

@brydavis
Created August 27, 2019 17:53
Show Gist options
  • Save brydavis/0b8d4ed47d75fcf26617c1a5c91443aa to your computer and use it in GitHub Desktop.
Save brydavis/0b8d4ed47d75fcf26617c1a5c91443aa to your computer and use it in GitHub Desktop.
Examples of creating and using decorators in Python
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@brydavis
Copy link
Author

brydavis commented Aug 27, 2019

Notice that in the last example, we are NOT using decorators and yet achieve the same result.

In fact, we are using a couple of simple functions and a closure.

Like many features in Python, decorators may not always provide the simplest (or even Pythonic) way to write code.

Use wisely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment