Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
decorators
#4
Hopefully this helps
def perma_set_first_param_decorator(x):
    """
    Decorates a two-argument function, replacing the first argument
    with the provided x value here.
    """
    def wrapper(f):
        return lambda y: f(x, y)

    return wrapper

@perma_set_first_param_decorator(2)
def add(first, second):
    return first + second

print(add(5)) # prints 7
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 489 Feb-24-2024, 06:12 AM
Last Post: Gribouillis
  Does @ at sign used for tother than decorators? ggpython000 1 598 Oct-12-2023, 09:08 AM
Last Post: buran
  Variable Scopes Decorators oclmedyb 6 2,813 Jan-15-2021, 02:13 PM
Last Post: oclmedyb
  Decorators and return statements JonEdward 2 1,952 Jul-24-2020, 05:02 PM
Last Post: JonEdward
  How to print cache from Decorators with Memoization OlgaM 2 2,126 Jan-29-2020, 05:06 PM
Last Post: OlgaM
  Python decorators. dodiko1d 0 9,830 Oct-13-2019, 10:23 AM
Last Post: dodiko1d
  Decorators yksingh1097 2 2,581 Aug-14-2018, 01:44 PM
Last Post: yksingh1097
  learning decorators Prince_Bhatia 6 3,394 Aug-13-2018, 02:28 PM
Last Post: Prince_Bhatia
  decorators within decorators mp3909 6 4,372 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