On Fri, Aug 23, 2019 at 10:18 AM Cameron Simpson <c...@cskk.id.au> wrote: > As Michael says, "you can always read from a parent scope if the name > hasn't been used by the local scope". What this means is this: > > _MODULE_LEVEL_CACHE = {} > > def factors_of(n): > factors = _MODULE_LEVEL_CACHE.get(n) > if factors is None: > factors = factorise(n) > _MODULE_LEVEL_CACHE[n] = factors > return factors
Note that this is still using a global variable, even though it isn't using the "global" keyword. The two concepts are related but distinct. ChrisA -- https://mail.python.org/mailman/listinfo/python-list