[IronPython] Named Tuple and IronPython 2

Michael Foord fuzzyman at voidspace.org.uk
Sun Sep 21 22:02:49 CEST 2008


Dino Viehland wrote:
> Not too long ago I prototyped a frames implementation including making _getframe work - but it doesn't include locals in the frames.  I guess in this case it would work just fine.
>
> The downside is it results in a 50% perf degrade on Pybench when calling recursive functions.   But we're already really fast calling functions so maybe that's acceptable.  Anyway it's something we can consider for a post-2.0 release (maybe w/ a command line option to control its presence) but I came up with the prototype too late to go adding it to 2.0.
>   

A frames implementation with a per engine switch would be fantastic! I'm 
sure you can work on performance. :-)

Michael



> -----Original Message-----
> From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Michael Foord
> Sent: Friday, September 19, 2008 5:27 AM
> To: Discussion of IronPython
> Subject: [IronPython] Named Tuple and IronPython 2
>
> Hello all,
>
> At PyCon UK Raymond Hettinger showed off the Named Tuple; a very useful recipe for creating tuples with named fields. It is becoming part of the standard library in Python 2.6.
>
> http://code.activestate.com/recipes/500261/
>
>  >>> from namedtuple import namedtuple
>  >>> thing = namedtuple('thing', ('whizz', 'pop'))  >>> thing <class '__builtin__.thing'>  >>> i = thing(1, 2)  >>> i.whizz
> 1
>  >>> i.pop
> 2
>  >>> w, p = i
>  >>> w, p
> (1, 2)
>  >>> i
> thing(whizz=1, pop=2)
>  >>>
>
> I've attached a modified version that works with IronPython 2 B5 (it doesn't work with 2B4 due to a very odd bug that is now fixed).
>
> The only change needed was to comment out the use of 'sys._getframe'
> which is there for pickle support.
>
> It is only conditionally used, because Jython didn't support this either
> - but on Jython _getframe wasn't defined at all so the conditional check fails on IronPython:
>
>     # Bypass this step in enviroments where
>     # sys._getframe is not defined (Jython for example).
>     if hasattr(_sys, '_getframe'):
>         result.__module__ = _sys._getframe(1).f_globals['__name__']
>
> I'll suggest a modification to the recipe that works with IronPython. A better solution would be to implement '_getframe' of course... :-)
>
> Michael Foord
>
> --
> http://www.ironpythoninaction.com/
> http://www.voidspace.org.uk/
> http://www.trypython.org/
> http://www.ironpython.info/
> http://www.resolverhacks.net/
> http://www.theotherdelia.co.uk/
>
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>   


-- 
http://www.ironpythoninaction.com/
http://www.voidspace.org.uk/
http://www.trypython.org/
http://www.ironpython.info/
http://www.theotherdelia.co.uk/
http://www.resolverhacks.net/




More information about the Ironpython-users mailing list