New Python 3.0 string formatting - really necessary?

Steve Holden steve at holdenweb.com
Fri Dec 19 23:02:10 EST 2008


Steven D'Aprano wrote:
> On Fri, 19 Dec 2008 10:25:30 -0700, Michael Torrie wrote:
> 
>> So funny that now that Python 3.0 is actually released we have people
>> acting all surprised like they've never seen any of the new features in
>> Python 3.0 coming.  However these features have been discussed for
>> years!  And debated!
> 
> Debated by who? The entire Python-using community? Every single Python 
> programmer? Or just the small proportion of Python developers who are 
> also core developers?
> 
> Are you *really* surprised that some people had never heard of the 
> changes being debated until it was too late?
> 
It isn't the least surprising that some people have been taken by
surprise by the changes. Neither is it surprising that some of them
don't like the changes that much. However, at least in the open source
world one has the *opportunity* to make one's voice heard and one's
opinion known, even thought he majority prefer to remain consumers of
the output of open source projects.

Where commercial projects are concerned the major influence one has is a
post-facto vote with one's wallet.

I hope, however, that those who don't like the changes but didn't bother
to track developments don't feel in any way disenfranchised. They are
still welcome to make their input, and of course there is nothing to
stop them keeping Python 2.X alive for as long as they wish.

[misconception about print's role]

>> Furthermore, the new {}
>> notation allows many, many more options for formatting to be used.  Want
>> to display a floating point number with $#.## notation, and ($#.##) for
>> negative?  It's all now possible.  Couldn't be done before.
> 
> Of course it could be. You just needed to write your own formatting 
> engine. What you mean is that it couldn't be done with % formatting and 
> nothing else. 
> 
> 
>> In short, this is a huge improvement, and backwards compatibility is
>> preserved for the 2.x style for those that wish it.
> 
> 
> There clearly is a need for a more heavyweight formatting solution than % 
> and string.Template. There are things that can't be done easily with % 
> alone, and format() will make them much simpler. I have no objection to 
> the addition of the format() method (although I wonder whether it might 
> have been better as a function).
> 
That's doubtless a debate that will play for a long time, with no really
clear advantage either way. Programmers just like to debate these
things. Of course it's a trivial addition:

def format(s, *args, **kw):
    return s.format(*args, **kw)

[I put **kw in becuase it's easier than checking the docs to se whether
keyword arguments are specified]. This doesn't mean there won't be
fifteen more posts on this thread about it.

regards
 Steve
-- 
Steve Holden        +1 571 484 6266   +1 800 494 3119
Holden Web LLC              http://www.holdenweb.com/




More information about the Python-list mailing list