Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #33784

Re: Yet another Python textbook

From Terry Reedy <tjreedy@udel.edu>
Subject Re: Yet another Python textbook
Date 2012-11-21 23:04 -0500
References (4 earlier) <31a82817-8c9b-4dd2-a468-89d8d081fd1b@googlegroups.com> <mailman.96.1353445247.29569.python-list@python.org> <50AD0962.5080002@ncf.ca> <CAPTjJmr55ZjpF9RBog39QZyTRixh=tTJH-5_pu3YTL4hWmfCAg@mail.gmail.com> <CAN1F8qXksLhbwb-DsvpcMdQDTkwWp1u92F7yObS7=TncvT9xwQ@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.191.1353557089.29569.python-list@python.org> (permalink)

Show all headers | View raw


On 11/21/2012 6:21 PM, Joshua Landau wrote:

> Since we've decided to derail the conversation...
>
> "{}".format() is a blessing an "" % () should go. "%" has no relevance
> to strings, is hard to "get" and has an appalling* syntax. Having two
> syntaxes just makes things less obvious, and the right choice rarer.
>
> str.format is also really easy. I don't understand what makes you disagree.
>
> Easy vs easier:
>
>  >>> "%s %s %s" % (1, 2, 3)
> '1 2 3'
>
>  >>> "{} {} {}".format(1, 2, 3)
> '1 2 3'

You forgot the cases where % formatting has to be special cased.
 >>> "The answer is {}.".format(1)
'The answer is 1.'
 >>> "The answer is {}.".format((1,))
'The answer is (1,).'
 >>> "The answer is %s" % 1
'The answer is 1'
 >>> "The anwser is %s" % (1,)
'The answer is 1'
 >>> "The answer is %s" % ((1,),)
'The answer is (1,)'


-- 
Terry Jan Reedy

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: Yet another Python textbook Chris Angelico <rosuav@gmail.com> - 2012-11-20 19:09 +1100
  Re: Yet another Python textbook wxjmfauth@gmail.com - 2012-11-20 06:57 -0800
    Re: Yet another Python textbook Chris Angelico <rosuav@gmail.com> - 2012-11-21 08:00 +1100
      Re: Yet another Python textbook wxjmfauth@gmail.com - 2012-11-21 06:49 -0800
      Re: Yet another Python textbook wxjmfauth@gmail.com - 2012-11-21 06:49 -0800
      Re: Yet another Python textbook "Colin J. Williams" <cjw@ncf.ca> - 2012-11-21 12:03 -0500
        Re: Yet another Python textbook Chris Angelico <rosuav@gmail.com> - 2012-11-22 09:17 +1100
          Re: Yet another Python textbook "Colin J. Williams" <cjw@ncf.ca> - 2012-11-22 07:24 -0500
            Re: Yet another Python textbook Ian Kelly <ian.g.kelly@gmail.com> - 2012-11-22 11:27 -0700
              Re: Yet another Python textbook "Colin J. Williams" <cjw@ncf.ca> - 2012-11-22 17:41 -0500
                Re: Yet another Python textbook Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-11-23 03:26 +0000
            Re: Yet another Python textbook Terry Reedy <tjreedy@udel.edu> - 2012-11-22 17:12 -0500
        Re: Yet another Python textbook Dave Angel <d@davea.name> - 2012-11-21 17:58 -0500
        Re: Yet another Python textbook Ian Kelly <ian.g.kelly@gmail.com> - 2012-11-21 16:11 -0700
        Re: Yet another Python textbook Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-11-21 23:26 +0000
        Re: Yet another Python textbook Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-11-21 23:32 +0000
        Re: Yet another Python textbook Ian Kelly <ian.g.kelly@gmail.com> - 2012-11-21 17:19 -0700
        Re: Yet another Python textbook Terry Reedy <tjreedy@udel.edu> - 2012-11-21 23:04 -0500
    Re: Yet another Python textbook Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-11-20 21:55 +0000
    Re: Yet another Python textbook Chris Angelico <rosuav@gmail.com> - 2012-11-21 09:25 +1100

csiph-web