[IronPython] Named Tuple and IronPython 2
fuzzyman at voidspace.org.uk
Fri Sep 19 14:26:54 CEST 2008
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.
>>> from namedtuple import namedtuple
>>> thing = namedtuple('thing', ('whizz', 'pop'))
>>> i = thing(1, 2)
>>> w, p = i
>>> w, p
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... :-)
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
More information about the Ironpython-users