Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Functional Python Programming
  • Toc
  • feedback
Functional Python Programming

Functional Python Programming

By : Steven F. Lott
4 (9)
close
Functional Python Programming

Functional Python Programming

4 (9)
By: Steven F. Lott

Overview of this book

This book is for developers who want to use Python to write programs that lean heavily on functional programming design patterns. You should be comfortable with Python programming, but no knowledge of functional programming paradigms is needed.
Table of Contents (18 chapters)
close
17
Index

Adding a parameter to a decorator


A common requirement is to customize a decorator with additional parameters. Rather than simply creating a composite , we're doing something a bit more complex. We're creating . We've applied a parameter, c, as part of creating the wrapper. This parameterized composite,, can then be used with the actual data, x.

In Python syntax, we can write it as follows:

@deco(arg)
def func( ):
    something

This will provide a parameterized deco(arg) function to the base function definition.

The effect is as follows:

def func( ):
    something
func= deco(arg)(func)

We've done three things and they are as follows:

  1. Define a function, func.

  2. Apply the abstract decorator, deco(), to its arguments to create a concrete decorator, deco(arg).

  3. Apply the concrete decorator, deco(arg), to the base function to create the decorated version of the function, deco(arg)(func).

A decorator with arguments involves indirect construction of the final function. We seem to have moved beyond merely...

bookmark search playlist font-size

Change the font size

margin-width

Change margin width

day-mode

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Delete Bookmark

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete