Undefined
By: Guest | Date: Oct 27 2015 15:15 | Format: Python | Expires: never | Size: 528 B | Hits: 840
- class iget(object):
- """A descriptor to make the creation of named tuples easier."""
- def __init__(self, i):
- """Store the index of the tuple's item to access."""
- self.i = i
- def __get__(self, instance, owner=None):
- """Access the tuple item that I am about."""
- return instance[self.i]
- class example(tuple):
- spam = iget(0)
- eggs = iget(1)
- ham = iget(2)
- x = example('foo', 'bar', 'bas')
- assert x.spam == 'foo'
- assert x.eggs == 'bar'
- assert x.ham == 'bas'
Latest pastes
2 days ago
3 days ago
3 days ago
4 days ago
5 days ago