import collections
Thing = collections.namedtuple('thing', 'color rotation direction')
thing1 = Thing(color = 'blue', rotation = 90, direction = 'south')
thing2 = Thing(color = 'green', rotation = -90, direction = 'west')
for t in [ thing1, thing2 ]:
print('%s-colored thing rotated %d degrees %s' % t)
Trying to figure out the analogue of Python 2 % string formatting in Python 3. Of course the print() call above works in Python 3, but I've been struggling trying to figure out how to do it using format().
This works, but does not seem very Pythonic:
print('{}-colored thing rotated {} degrees {}'.format(t[0], t[1], t[2]))
I tried
print('{}-colored thing rotated {} degrees {}'.format(t[:]))
but I get
IndexError: tuple index out of range