[Python-ideas] Briefer string format

Eric Fahlgren ericfahlgren at gmail.com
Tue Jul 21 04:43:29 CEST 2015


Eric V. Smith wrote: 
> Right. But why re-implement that, instead of making it:
> '{[n]}'.format(a)?

Consider also the case of custom formatters.  I've got one that overloads
format_field, adds a units specifier in the format, which then uses our
model units conversion and writes values in the current user-units of the
system:

   x = body.x_coord # A "Double()" object with units of length.
   print(f'{x:length:.3f}') # Uses the "length" string to perform a units
conversion much as "!r" would invoke "repr()".

I think your proposal above handles my use case the most cleanly.

Another Eric



More information about the Python-ideas mailing list