string formatting
harrismh777
harrismh777 at charter.net
Fri May 6 15:22:25 EDT 2011
Steven D'Aprano wrote:
> It's perfectly safe to continue using % formatting, if you choose.
>
I would hope so, since its the way in most of the books, much of the
doc and a majority of the code...
I don't really like the old style, not because there is anything
wrong with it, because its an obvious carry-over from the cryptic
formatting style of 'C' printf(), and others. It seems to me that the
purpose of formatting is to make output clear, and therefore the output
formatting style itself should be clear and clean.
On the other hand, among the three styles listed by the OP
(1) "the %s is %s" % ('sky', 'blue')
(2) "the {0} is {1}".format('sky', 'blue')
(3) "the {} is {}".format('sky', 'blue')
... they all *feel* good... I mean, they're all clear, clean,
precise...
On the other hand, while any 'C' programmer is able to see instantly
that (1) is a some type of formatting construct, (2) & (3) are clear and
obvious formatting constructs, even for newbies and esp. for non 'C'
programmers.
On the other hand, at this point, it seems that this is personal
preference issue completely. So, if the book says you can do it, and
there is no formal deprecation process in the works, feel free to
express yourself with the style that best suits 'you'.
On the other hand,..... :)
kind regards,
m harris
More information about the Python-list
mailing list