>>> class Point(namedtuple('Point', 'x y')):
_make = classmethod(tuple.__new__)
def _replace(self, _map=map, **kwds):
- return self._make(_map(kwds.pop, ('x', 'y'), self))
+ return self._make(_map(kwds.get, ('x', 'y'), self))
Default values can be implemented by using :meth:`_replace` to
customize a prototype instance::
'Point class with optimized _make() and _replace() without error-checking'
_make = classmethod(tuple.__new__)
def _replace(self, _map=map, **kwds):
- return self._make(_map(kwds.pop, ('x', 'y'), self))
+ return self._make(_map(kwds.get, ('x', 'y'), self))
print Point(11, 22)._replace(x=100)