Creating a decorator / cache for checking global variable
问题 I've quite a few functions that uses some global variables to hold an object to be reused throughout the library, e.g.: from some.other.lib import Object1, Object2, Object3, Object4, Object5 def function1(input): global _object1 try: _object1 except NameError: _object1 = Object1 return _object1.func1(input) def function2(input): global _object2 try: _object2 except NameError: _object2 = Object2 # Use function1 to do something to the input return _object2.func2(function1(input)) def function3