>>> print '%(language)s has %(number)03d quote types.' % \
... {"language": "Python", "number": 2}
Instead of this:
print "%s has %03d" % ( "python", "2" )
6 years of python development, and I never found this little beauty. Fail.
Hope this helps someone else.
Cal
Also very useful in translations where the order of the pieces
may have to change, allowing the translator to put them where
needed rather than constraining the translator to the order in
which the data is passed.
-tkc
And fantasticly useful when a given value is needed more than once
in a string, or when you have a collection of available values and a
passed in or chosen format string, such that some values may not
be used at all.
Goes to show, no matter how long you've used something, even if it's
day in day out, there's always something new to learn!
> --
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To post to this group, send email to django...@googlegroups.com.
> To unsubscribe from this group, send email to django-users...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
>
>
Crikey, if you didn't know about that one, you probably don't know
about this one either:
>>> fmt = "{} shalt thou not count, neither count thou {}, excepting that thou then proceed to {}. {} is right out!"
>>> fmt.format('four', 'two', 'three', 'five')
'four shalt thou not count, neither count thou two, excepting that
thou then proceed to three. five is right out!'
http://docs.python.org/library/string.html#format-string-syntax
Cheers
Tom