[Python-ideas] String formatting and namedtuple
lie.1296 at gmail.com
Tue Feb 10 11:43:34 CET 2009
I've been experimenting with namedtuple, it seems that string formatting
doesn't recognize namedtuple as mapping.
from collections import namedtuple
Nt = namedtuple('Nt', ['x', 'y'])
nt = Nt(12, 32)
print 'one = %(x)s, two = %(y)s' % nt
# output should be:
one = 12, two = 32
currently, it is possible to use nt._asdict() as a workaround, but I
think it will be easier and more intuitive to be able to use namedtuple
directly with string interpolation
Sorry, if this issue has been discussed before.
More information about the Python-ideas