Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #8056
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!newsgate.cistron.nl!newsgate.news.xs4all.nl!194.109.133.85.MISMATCH!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'example:': 0.03; '2.x': 0.05; 'attributes': 0.05; 'int': 0.05; 'chunk': 0.07; 'formatting': 0.07; 'terry': 0.07; 'python': 0.08; '3.0,': 0.09; 'operator,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'statement.': 0.09; 'subject:string': 0.09; 'tuple': 0.09; 'pm,': 0.10; '>>>': 0.12; 'def': 0.12; 'described': 0.14; 'wrote:': 0.14; 'finney': 0.16; 'iterator': 0.16; 'new-style': 0.16; 'reedy': 0.16; 'subject:formatting': 0.16; 'subject:syntax': 0.16; 'url:format': 0.16; 'wins': 0.16; '{0}': 0.16; 'subject:was': 0.16; 'jan': 0.20; 'header:In-Reply-To:1': 0.21; "haven't": 0.22; 'indicating': 0.23; 'objects': 0.23; 'code': 0.24; 'preferred': 0.26; 'missed': 0.26; 'string': 0.26; 'object': 0.26; 'testing': 0.27; 'example': 0.27; 'class': 0.29; 'bit': 0.30; 'chase': 0.30; 'style.': 0.30; 'tuples': 0.30; 'url:library': 0.31; 'header:X -Complaints-To:1': 0.32; 'does': 0.33; 'to:addr:python-list': 0.33; 'operations': 0.33; 'lines': 0.33; "i've": 0.33; '...': 0.34; 'source': 0.34; 'there': 0.35; 'header:User-Agent:1': 0.35; 'subject:What': 0.35; 'test': 0.35; 'subject:new': 0.37; 'members': 0.37; 'url:docs': 0.37; 'case': 0.37; 'url:python': 0.38; 'received:org': 0.38; 'url:org': 0.38; 'subject:: ': 0.38; 'some': 0.38; 'should': 0.39; 'unless': 0.39; 'abuse': 0.39; 'header:Mime-Version:1': 0.39; 'difficult': 0.39; 'to:addr:python.org': 0.39; 'feature': 0.40; 'more': 0.60; 'link': 0.64; 'here': 0.66; 'special': 0.66; 'became': 0.67; 'subject:this': 0.76; 'flexible,': 0.84; '\xe2\x80\x9cthis': 0.84 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Terry Reedy <tjreedy@udel.edu> |
| Subject | Re: new string-formatting preferred? (was "What is this syntax ?") |
| Date | Mon, 20 Jun 2011 22:17:07 -0400 |
| References | <mailman.178.1308554725.1164.python-list@python.org> <87pqm8qh7m.fsf@benfinney.id.au> <4DFFE9D5.30300@tim.thechases.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8; format=flowed |
| Content-Transfer-Encoding | quoted-printable |
| X-Gmane-NNTP-Posting-Host | rain.gmane.org |
| User-Agent | Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.17) Gecko/20110414 Lightning/1.0b2 Thunderbird/3.1.10 |
| In-Reply-To | <4DFFE9D5.30300@tim.thechases.com> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.209.1308622639.1164.python-list@python.org> (permalink) |
| Lines | 48 |
| NNTP-Posting-Host | 82.94.164.166 |
| X-Trace | 1308622639 news.xs4all.nl 49184 [::ffff:82.94.164.166]:56169 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:8056 |
Show key headers only | View raw
On 6/20/2011 8:46 PM, Tim Chase wrote:
> On 06/20/2011 05:19 PM, Ben Finney wrote:
>> “This method of string formatting is the new standard in
>> Python 3.0, and should be preferred to the % formatting
>> described in String Formatting Operations in new code.”
>>
>> <URL:http://docs.python.org/library/stdtypes.html#str.format>
>
> Is there a good link to a thread-archive on when/why/how .format(...)
> became "preferred to the % formatting"?
That is a controversial statement.
> I haven't seen any great wins of
> the new formatting over the classic style. Is there some great feature
> of new-style formatting that I've missed out on that obviates bajillions
> of lines of 2.x code?
It does not abuse the '%' operator, it does not make a special case of
tuples (a source of bugs), and it is more flexible, especially
indicating objects to be printed. Here is a simple example from my code
that would be a bit more difficult with %.
multi_warn = '''\
Warning: testing multiple {0}s against an iterator will only test
the first {0} unless the iterator is reiterable; most are not.'''.format
...
print(multiwarn('function'))
...
print(multiwarn('iterator'))
Here is a more complex example:
class chunk():
def __init__(self, a, b):
self.a,self.b = a,b
c=chunk(1, (3,'hi'))
print('{0.__class__.__name__} object has attributes int a <{0.a}> and
tuple b with members <{0.b[0]}> and <{0.b[1]}>'.format(c))
>>>
chunk object has attributes int a <1> and tuple b with members <3> and <hi>
--
Terry Jan Reedy
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: What is this syntax ? Claudiu Popa <cpopa@bitdefender.com> - 2011-06-20 10:18 +0300
Re: What is this syntax ? Ben Finney <ben+python@benfinney.id.au> - 2011-06-21 08:19 +1000
Re: new string-formatting preferred? (was "What is this syntax ?") Tim Chase <python.list@tim.thechases.com> - 2011-06-20 19:46 -0500
Re: new string-formatting preferred? (was "What is this syntax ?") Terry Reedy <tjreedy@udel.edu> - 2011-06-20 22:17 -0400
Re: new string-formatting preferred? (was "What is this syntax ?") Tim Chase <python.list@tim.thechases.com> - 2011-06-21 06:33 -0500
Re: new string-formatting preferred? (was "What is this syntax ?") Terry Reedy <tjreedy@udel.edu> - 2011-06-21 18:19 -0400
Re: new string-formatting preferred? (was "What is this syntax ?") Tim Chase <python.list@tim.thechases.com> - 2011-06-21 18:02 -0500
csiph-web