3 ms·
What's the complaint? That Python doesn't have anonymous functions? Sure, that would be nice, but his example would work fine if he declared the function with a
by ptx 11y ago
What's the complaint? That Python doesn't have anonymous functions? Sure, that would be nice, but his example would work fine if he declared the function with a temporary name first.
>>> for page in ["index", "about", "contact"]:
... def _(p=page):
... print("Hello, I'm", p)
... globals()[page] = _
...
>>> index()
Hello, I'm index
>>> about()
Hello, I'm about
>>> contact()
Hello, I'm contact