I need to write functions that return locals() as follows, def func1(): a = 1 return locals() def func2(): b = 2 return locals() Can I write a decorator that it can automately do this conversion def func1() a = 1 ---> def func1(): a = 1 return locals()