Oct. 7, 2020
6:43 a.m.
New improved version: def submodule(f): co = f.__code__ i = len(co.co_consts) b = bytes([0x64, i, 0x83, 0x0, 0x53, 0x0]) f.__code__ = co.replace( co_consts = co.co_consts + (locals,), co_code = co.co_code[:-4] + b ) return type(f.__name__, (), f()) @submodule def Stuff(): def f1(): print("First function") f2() def f2(): print("Second function") Stuff.f1() -- Greg