Skip to content

Instantly share code, notes, and snippets.

@Sllayan
Last active January 1, 2025 13:03
Show Gist options
  • Select an option

  • Save Sllayan/45d8dc7d8b47a2a5c72447907e0b0c07 to your computer and use it in GitHub Desktop.

Select an option

Save Sllayan/45d8dc7d8b47a2a5c72447907e0b0c07 to your computer and use it in GitHub Desktop.

Revisions

  1. Sllayan revised this gist Jan 1, 2025. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,3 @@
    # Python decorator

    ### This is an example of simple decorator in Python
    ## This is an example of simple decorator in Python
  2. Sllayan revised this gist Nov 23, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,3 @@
    # Python decorator

    ### This is an example of simple python decorator
    ### This is an example of simple decorator in Python
  3. Sllayan revised this gist Nov 23, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,3 @@
    # Python decorator

    This is an example of simple python decorator
    ### This is an example of simple python decorator
  4. Sllayan revised this gist Nov 23, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,3 @@
    ### Python decorator
    # Python decorator

    This is an example of simple python decorator
  5. Sllayan created this gist Nov 23, 2024.
    3 changes: 3 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    ### Python decorator

    This is an example of simple python decorator
    22 changes: 22 additions & 0 deletions main.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    # Decorator function
    def my_decorator(func):
    def wrapper():
    print('Anything that needs to be done before the function is called.')
    func()
    print('Anything that needs to be done after the function is called.')
    return wrapper

    # First usecase
    def say_hello():
    print('hello')

    say_it = my_decorator(say_hello)

    say_it()

    # Second usecase
    @my_decorator
    def say_hello():
    print('hello')

    say_hello()