Skip to content

Instantly share code, notes, and snippets.

@cosmin
cosmin / inject.py
Created January 6, 2014 05:59
Function to create a new class using a base class with substituted global scope
import types
def clone(original, **newg):
return types.FunctionType(original.func_code,
dict(original.func_globals, **newg),
original.func_name,
original.func_defaults,
original.func_closure)
def inject(cls, **newg):