
On Mon, 5 Dec 2022 at 08:34, Bruce Leban <bruce@leban.us> wrote:
I can put that in a function which still leaves the function in scope:
def __create_thing(): part1 = (some calculation) part2 = (some other calculation) return combine(part1, part2) THING = __create_thing()
If we had a top-level-only local statement, I might use it but note that it's still clumsy since I have to make THING non-local:
local: part1 = (some calculation) part2 = (some other calculation) nonlocal THING THING = combine(part1, part2)
# put this in your site.py or whatever so it's always available def scope(f): return f() # then do this @scope def THING(): part1 = (some calculation) part2 = (some other calculation) return combine(part1, part2) It's better than multiline lambda, and has all the benefits of a nested scope. It doesn't leave the function lying around - it reuses the name for the value the function returns. ChrisA