Python Hooks

From PeformIQ Upgrade
Revision as of 16:02, 20 July 2017 by PeterHarding (talk | contribs) (Created page with " =Hook Functions & Wrappers= <pre> import whatever import functools def prefix_function(function, prefunction): @functools.wraps(function) def run(*args, **kwargs):...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Hook Functions & Wrappers

import whatever
import functools

def prefix_function(function, prefunction):
    @functools.wraps(function)
    def run(*args, **kwargs):
        prefunction(*args, **kwargs)
        return function(*args, **kwargs)
    return run

def this_is_a_function(parameter):
    pass # Your own code here that will be run before

whatever.this_is_a_function = prefix_function(
    whatever.this_is_a_function, this_is_a_function)