Undefined
By: Guest | Date: Oct 27 2015 15:15 | Format: Python | Expires: never | Size: 528 B | Hits: 842
- 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
1 hours ago
11 hours ago
1 days ago
2 days ago
2 days ago