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

Barry Warsaw barry at python.org
Thu Aug 16 22:16:49 CEST 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Aug 16, 2007, at 3:52 PM, skip at pobox.com wrote:
> STeVe> I honestly can't see the point of keeping this::
>>>>>> '%-10s bought %02i apples for %3.2f' % ('John', 8, 3.78)
> STeVe> 'John bought 08 apples for 3.78'
>> STeVe> alongside this::
>>>>>> '{0:-10} bought {1:02i} apples for {2:3.2f}'.format('John', 8, 
>>>>> 3.78)
> STeVe> 'John bought 08 apples for 3.78'
>> STeVe> They're so similar I don't see why you think the latter 
> is no
> STeVe> longer "easy and powerful".
>> You mean other than:
>> * the new is more verbose than the old
> * the curly braces and [012]: prefixes are just syntactic sugar 
> when
> converting old to new
> * in situations where the format string isn't a literal that 
> mechanical
> translation from old to new won't be possible
> * lots of people are familiar with the old format, few with the new

There's one other problem that I see, though it might be minor or 
infrequent enough not to matter. %s positional placeholders are 
easily to generate programmatically than {#} placeholders. Think 
about translating this:
def make_query(flag1, flag2):
 base_query = 'SELECT %s from %s WHERE name = %s '
 if flag1:
 base_query += 'AND age = %s '
 if flag2:
 base_query += 'AND height = %s '
 base_query = 'AND gender = %s'
 return base_query
- -Barry
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (Darwin)
iQCVAwUBRsSwsXEjvBPtnXfVAQLyPgP+P/bnNZhZUGbAcM6lDJdACVYmEFh3bGDR
NJH874DLXp7fsn5iLJ3Fel7eiWqLZ0/lvGYEmAAz/4SYagKFnrYAFTsDKglFroiL
bHzZBKHHuf/Db1oNJBcuQakpbhddX0WMu+XxcKXbgUK87tJE4kbaZPTjU8WF5XDW
EriR/UZBZ40=
=qHQs
-----END PGP SIGNATURE-----


More information about the Python-3000 mailing list

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