News for hackers. Stuff that matters.
Re:Dynamic, Generic Namespaces in Python Are a Pain by ptx on Saturday May 30, 2015 @05:38PM (#9631845)
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

There are no comments on this comment yet.