Skip to main content
Join the official 2019 Python Developers SurveyStart the survey!

A decorator for injecting global variables into function calls.

Project description


A function for injecting global variables into function calls.

Usage example:

A simple usage example is this:

from inject_globals import inject_globals

@inject_globals(a = "Hello", b = "World")
def hello():
    print(f"{a} {b}")


However, that example is somewhat silly. It's power shows up when you are creating other decorators, like this one:

def run_n_times(n):
    def middle(func):
        from functools import wraps

        def inner(*args, **kwargs):
            r = []
            for i in range(1, n + 1):
                r.append(inject_globals(it = i)(func)(*args, **kwargs))
            return r
        return inner
    return middle

def foo():
    return f"This is the iteration #{it}."

assert foo() == ["This is the iteration #1.", "This is the iteration #2.", "This is the iteration #3."]

Project details

Release history Release notifications

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for inject-globals, version
Filename, size File type Python version Upload date Hashes
Filename, size inject-globals- (2.0 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page