[Python-Dev] Py2.6 ideas (original) (raw)
Phillip J. Eby pje at telecommunity.com
Tue Feb 20 18:57:32 CET 2007
- Previous message: [Python-Dev] Py2.6 ideas
- Next message: [Python-Dev] generic async io (was: microthreading vs. async io)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
At 10:17 AM 2/20/2007 +0000, Fuzzyman wrote:
Michele Simionato wrote:
>Raymond Hettinger <raymond.hettinger verizon.net> writes: > > >>* Add a pure python namedtuple class to the collections module. I've been >>using the class for about a year and found that it greatly improves the >>usability of tuples as records. >>http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/500261 >> >> >[snip..] >4. I want help(MyNamedTuple) to work well; in particular it should > display the right module name. That means > that in the m dictionary you should add a module attribute: > > module = sys.getframe(1).fglobals['name'] > > > Hello all, If this is being considered for inclusion in the standard library, using _getframe' hackery will guarantee that it doesn't work with alternative implementations of Python (like IronPython at least which doesn't have Python stack frames).
Here's a way that doesn't need it:
@namedtuple def Point(x,y): """The body of this function is ignored -- but this docstring will be used for the Point class"""
This approach also gets rid of the messy string stuff, and it also allows one to specify default values. The created type can be given the function's name, module, and doc.
- Previous message: [Python-Dev] Py2.6 ideas
- Next message: [Python-Dev] generic async io (was: microthreading vs. async io)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]