.format won't display my value with 2 decimal places: Why?

Chris Kaynor ckaynor at zindagigames.com
Mon Jan 25 15:40:32 EST 2016


On Mon, Jan 25, 2016 at 9:48 AM, Chris Angelico <rosuav at gmail.com> wrote:

> On Tue, Jan 26, 2016 at 4:32 AM, Random832 <random832 at fastmail.com> wrote:
> > On Mon, Jan 25, 2016, at 12:23, Chris Angelico wrote:
> >> if some translations don't use a token at all,
> >
> > I'm not sure what situation that would be reasonable in.
>
> I don't do much with different human languages, but it's possible that
> you might build up a message in a variety of different ways, and
> include tokens differently. Maybe you'd include a product name in two
> different places, and each translation would get to choose which of
> the lines includes it. Maybe there's a fixed string that carries the
> sense of what you're saying better than the parameterized one does, so
> you ignore the parameter. It's the same flexibility as reordering
> tokens, but some tokens get reordered to nowhere. (Is it still a
> teleportation spell when the destination is oblivion? -- Venser)


One of the most useful reasons to not require all arguments be used is when
using the string as part of a templating system, though in those cases,
using named (over positional) arguments makes it easiest.

While I have not seen any cases where some arguments go unused in other
languages, it is often useful to generate a bunch of data, and let a
designer or translator decide on the exact arguments to use in a specific
string. Often times, this will mean using different template strings, which
only use a subset (and sometimes even none) of the arguments.

While not using Python, a project I am working on uses this for some of the
data being displayed. In this case, some of the template strings do not use
any template values, while others use multiple, but rather than have to
special case each variation, it can just run the template strings though
formatting code. This is particularly useful in the cases where a quantity
is included, and variations are used for singular vs plural cases.



More information about the Python-list mailing list