New Python 3.0 string formatting - really necessary?

Luis M. González luismgz at gmail.com
Mon Dec 29 16:37:48 EST 2008


On 19 dic, 13:01, walterbyrd <walterb... at iname.com> wrote:
> I have not worked with Python enough to really know. But, it seems to
> me that more I look at python 3.0, the more I wonder if it isn't a
> step backwards.
>
> To me, it seems that this:
>
> print "%s=%d" % ('this',99)
>
> Is much easier, and faster, to type, and is also easier to read and
> understand. It also allows people to leverage their knowledge of C.
>
> This (if it's right) is much longer, and requires more special
> characters.
>
> print( "{0}={1}".format('this',99))
>
> Maybe it's worth all the extra trouble, and breaking backward
> compatibilty, and all. But, I never had the idea that the old way was
> all that big a problem. Of course, I could be wrong. Was the old way
> all that big of a problem?

Well, I was playing with python 3k a little bit and, as usual, after a
few minutes everything felt natural.
The new string formating is perhaps a little more typing, much is much
more clear and readable.
I know where it came from. Long ago, Guido took a look at Boo, which
is a python-like .NET language, and he posted a comment saying how
much he liked the string formating, which is identical to the new one
in python.

I still can't get used to add the parenthesis to "print", and this is
the only thing I don't like, but I'm sure there's a good reason for
this change...

Luis



More information about the Python-list mailing list