News for hackers. Stuff that matters.
Re:Functional programming in Python by TazeTSchnitzel on Friday May 11, 2012 @06:00PM (#3961657)
namedtuple is awesome, until you realise it works internally by using eval and generating the source code of a class.
Re:Functional programming in Python by benhoyt on Saturday May 12, 2012 @02:28PM (#3964706)
See also http://bugs.python.org/issue3974, where someone submits a patch for namedtuple that doesn't use exec. The maintainers reject it as less clear and probably slower. I agree there is "nothing unholy in using exec", though I found this weird at first too.
Re:Functional programming in Python by mattdeboard on Friday May 11, 2012 @06:03PM (#3961677)
namedtuple is still awesome. The fact that it's eval'ing a string to initialize it doesn't make that any less the case.

However, I'll agree that it would be disingenuous to say it's not a little peculiar, and surprising to see the source for it :)

Re:Functional programming in Python by slig on Friday May 11, 2012 @09:02PM (#3962231)
Why does it do that, instead of some other more pythonic way?
Re:Functional programming in Python by chimeracoder on Friday May 11, 2012 @06:03PM (#3961676)
And Lisps work internally by generating lists and evaluating those, but you don't see me complaining about macros!

In all seriousness, though, if I really wanted a functional implementation, I wouldn't be using Python. It's more just nice to know that I can create an object that's immutable and which functions more or less like a CLOS object, so that I can think in that mindset instead. Also, I believe it doesn't come with all of the hidden functions that it would otherwise.

In the end, if I really cared, I'd actually write a wrapper around the type() function.