Simple string formatting question

Ben Finney bignose+hates-spam at benfinney.id.au
Thu Apr 6 20:01:02 EDT 2006


"Steven D'Aprano" <steve at REMOVETHIScyber.com.au> writes:

> On Thu, 06 Apr 2006 22:16:05 +1000, Ben Finney wrote:
> > "Steven D'Aprano" <steve at REMOVEMEcyber.com.au> writes:
1> >> I'm looking for a format string similar to '%.3f' except that
> >> trailing zeroes are not included.
> > 
> > Can;t be done, to my knowledge. You specify a particular
> > precision, and the number will be formatted at that
> > precision. This matches the 'printf' behaviour that inspired
> > string formatting operations.
> 
> [...] would there be any interest in extending the formatting
> operations to include such a feature? It would (presumably) break
> compatibility with printf, but does that matter?

-1 from me. The concept of "precision" is fairly well defined; you're
talking about combining that with something more special-case.  In
general, "special cases aren't special enough to break the rules", and
the programemr should be forced to spell out what he's doing so that
it's obvious.

In the specific cases of the string formatting codes, they're a
special case that is a marginal win because of the large body of
existing experience with the standard C printf codes. That's weighed
against their considerable lack of readability; expand them to be
special for Python, and that "marginal win" is gone.

-- 
 \         "My girlfriend has a queen sized bed; I have a court jester |
  `\   sized bed. It's red and green and has bells on it, and the ends |
_o__)                                      curl up."  -- Steven Wright |
Ben Finney




More information about the Python-list mailing list