Python Forum
How can we override decorator?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can we override decorator?
#3
You can combine decorators by stacking them:

def decorator_one(func):
    def wrapper():
        print('decorator #1')
        func()
    return wrapper

def decorator_two(func):
    def wrapper():
        print('decorator the second')
        func()
    return wrapper

@decorator_one
@decorator_two
def hello():
    print('A duck!')

hello()
Output:
decorator #1 decorator the second A duck!
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
How can we override decorator? - by bhojendra - May-12-2019, 06:12 PM
RE: How can we override decorator? - by Gribouillis - May-12-2019, 11:03 PM
RE: How can we override decorator? - by ichabod801 - May-12-2019, 11:15 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  the order of running code in a decorator function akbarza 2 558 Nov-10-2023, 08:09 AM
Last Post: akbarza
  Curious about decorator syntax rjdegraff42 14 2,186 May-03-2023, 01:21 PM
Last Post: rjdegraff42
  python update binary object (override delivered Object properties) pierre38 4 1,801 May-19-2022, 07:52 AM
Last Post: pierre38
  dict class override: how access parent values? Andrey 1 1,667 Mar-06-2022, 10:49 PM
Last Post: deanhystad
  Due to MDLable ID does not have get attribute how to override on this jayyu 0 2,853 Dec-20-2021, 10:38 AM
Last Post: jayyu
  Override a library function that is not in __all__ Weird 7 3,323 Aug-23-2021, 05:03 PM
Last Post: Larz60+
  ABC Module and @property decorator, Pythonic Way? muzikman 21 5,822 Aug-18-2021, 06:08 PM
Last Post: muzikman
  decorator adamfairhall 0 1,577 Aug-18-2020, 08:38 AM
Last Post: adamfairhall
  Use of @property decorator ruy 16 6,671 Jun-09-2020, 05:29 PM
Last Post: buran
  Merge dicts without override chisox721 4 3,287 Jul-20-2019, 01:45 AM
Last Post: chisox721

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020