Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
decorators
#6
(Mar-19-2018, 05:31 PM)mp3909 Wrote: I now want to decorate this function so that the first argument is always multiplied by 4 and then added to the second argument.
From the way you describe it, your decorator will not care what the function it's decorating does. Am I correct in saying what you actually want is a decorator which multiplies the first argument by a value provided to the decorator, before calling the decorated function?

I believe that in either case, my example should be fairly adaptable. Feel free to give it a try, and we can work from there.
Reply


Messages In This Thread
decorators - by mp3909 - Mar-19-2018, 11:04 AM
RE: decorators - by Larz60+ - Mar-19-2018, 11:12 AM
RE: decorators - by mp3909 - Mar-19-2018, 03:44 PM
RE: decorators - by micseydel - Mar-19-2018, 05:19 PM
RE: decorators - by mp3909 - Mar-19-2018, 05:31 PM
RE: decorators - by micseydel - Mar-19-2018, 05:48 PM
RE: decorators - by mp3909 - Mar-19-2018, 05:56 PM
RE: decorators - by wavic - Mar-19-2018, 06:59 PM
RE: decorators - by mp3909 - Mar-19-2018, 08:18 PM
RE: decorators - by mp3909 - Mar-25-2018, 05:28 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Decorators @ annotation drcl 3 471 Feb-24-2024, 06:12 AM
Last Post: Gribouillis
  Does @ at sign used for tother than decorators? ggpython000 1 588 Oct-12-2023, 09:08 AM
Last Post: buran
  Variable Scopes Decorators oclmedyb 6 2,802 Jan-15-2021, 02:13 PM
Last Post: oclmedyb
  Decorators and return statements JonEdward 2 1,940 Jul-24-2020, 05:02 PM
Last Post: JonEdward
  How to print cache from Decorators with Memoization OlgaM 2 2,125 Jan-29-2020, 05:06 PM
Last Post: OlgaM
  Python decorators. dodiko1d 0 9,527 Oct-13-2019, 10:23 AM
Last Post: dodiko1d
  Decorators yksingh1097 2 2,575 Aug-14-2018, 01:44 PM
Last Post: yksingh1097
  learning decorators Prince_Bhatia 6 3,391 Aug-13-2018, 02:28 PM
Last Post: Prince_Bhatia
  decorators within decorators mp3909 6 4,359 Apr-02-2018, 09:47 AM
Last Post: hf8bm

Forum Jump:

User Panel Messages

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