[Python-3000] String formating operations in python 3k
Greg Ewing
greg.ewing at canterbury.ac.nz
Tue Apr 4 05:34:22 CEST 2006
Eric V. Smith wrote:
> Doesn't this violate Guido's "don't have a parameter that is always a
> constant that changes how a function operates" principle (or whatever
> its formal name is)?
It's not inconceivable that a function might want to
accept formatting parameters and pass them on to
another function which used format(). If there were
separate functions for the different formats, this
would be awkward.
Guido's principle applies when the parameter in
question alters the meaning so radically that it
seems inconceivable to want to vary it from one
call to another. I don't think that quite applies
here, although that's obviously a matter of
opinion.
I wouldn't object to having separate functions
available as an alternative for the cases where
you don't need the flexibility, which would be
most of the time.
> Or maybe a format() member of int and float, which take
> different parameters.
That would make it awkward to take a number which
might be an int or float and format it as a float --
you'd have to be careful to cast it to float first.
I don't see it as a matter of formatting different
types of object, but of having one type of object
(a number) and formatting it in different ways.
You could even consider 'd' to be a special case
of 'f' with 0 decimal places (although it isn't
quite).
--
Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury, | Carpe post meridiam! |
Christchurch, New Zealand | (I'm not a morning person.) |
greg.ewing at canterbury.ac.nz +--------------------------------------+
More information about the Python-3000
mailing list