Some python syntax that I'm not getting

Matt mattias.o.nilsson at gmail.com
Sat Dec 8 06:17:52 EST 2007


Think of it as using a name instead of a position for your "%s".

In addition to what others already said, I thought I'd add an example
of where this is useful.
One place where you don't just want to have a position is when doing
internatiolization.
When translating for example:
"I'm going by %(transport)s to %(place)s" % ( {'transport' : 'car',
'place' : 'mexico'} )

In another language, the 'place' and 'transport' might not be in the
same order in the sentence, so pretty much the only way to get it
right is to use named parameters instead of positions.



More information about the Python-list mailing list