[Python-3000] Please don't kill the % operator...

skip at pobox.com skip at pobox.com
Thu Aug 16 21:57:33 CEST 2007


 Brett> But how is::
 Brett> "{0} is happy to see {1}".format('Brett', 'Christian')
 Brett> that less easier to read than::
 Brett> "%s is happy to see %s" % ('Brett', 'Christian')
 Brett> ? Yes, PEP 3101 style is more to type but it isn't grievous; we
 Brett> have just been spoiled by the overloading of the % operator. And
 Brett> I don't know how newbies think these days, but I know I find the
 Brett> numeric markers much easier to follow then the '%s', especially
 Brett> if the string ends up becoming long.
If you decide to insert another format token in the middle the new is more
error-prone than the old:
 "{0} asks {1} if he is happy to see {1}".format('Brett', 'Skip', 'Christian')
 ^^^ whoops
vs:
 "%s asks %s if he is happy to see %s" % ('Brett', 'Skip', 'Christian')
Now extend that to format strings with more than a couple expansions.
 Brett> This is where the cranky python-dev'er comes in: PEP 3101 was
 Brett> published in April 2006 which is over a year ago! This is not a
 Brett> new PEP or a new plan.
Yes, but Python 3 is more real today than 15 months ago, hence the greater
focus now than before.
Skip


More information about the Python-3000 mailing list

AltStyle によって変換されたページ (->オリジナル) /