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


Groups > comp.lang.python > #75306

Re: What meaning of this ""hello %s you are %s years old" % x"

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.022
X-Spam-Evidence '*H*': 0.96; '*S*': 0.00; 'python,': 0.02; 'operator': 0.03; 'argument': 0.05; 'output': 0.05; 'string': 0.09; 'formatting': 0.09; 'style.': 0.09; 'cc:addr:python-list': 0.11; 'template': 0.14; 'downside': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'magic': 0.16; 'portable': 0.16; 'tuple': 0.16; 'tuples,': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'result.': 0.19; 'cc:addr:python.org': 0.22; 'mon,': 0.24; 'cc:2**0': 0.24; 'switch': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'message-id:@mail.gmail.com': 0.30; 'that.': 0.31; 'obscure': 0.31; 'operations.': 0.31; 'values.': 0.31; 'probably': 0.32; 'languages': 0.32; 'url:python': 0.33; 'cases': 0.33; 'older': 0.33; 'style': 0.33; "can't": 0.35; 'but': 0.35; 'received:google.com': 0.35; 'method': 0.36; 'url:org': 0.36; 'should': 0.36; 'url:library': 0.38; 'pm,': 0.38; 'rather': 0.38; 'that,': 0.38; 'ability': 0.39; 'extremely': 0.39; 'even': 0.60; 'subject:"': 0.60; 'new': 0.61; 'url:3': 0.61; 'details.': 0.61; 'real': 0.63; 'more': 0.64; 'details': 0.65; 'percent': 0.68; 'brand': 0.72; 'jul': 0.74; 'subject:hello': 0.83; 'subject:this': 0.83; 'compact,': 0.84; 'situations,': 0.84; 'subject:you': 0.87; 'ample': 0.91; 'to:none': 0.92; 'anywhere,': 0.93
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=nDDdqNgfx0tKgE4EGGCyjQ2KHjlD0ls0/w05VbCcVws=; b=RQkhbLZGiVUREQDDGdN72ksihwIdJIP5CCkyKrV1fKt7kI5RPiLZQqsqHWwU9Bx+9E +Aj+VJQ78++GccwjvxQ+9rhYBCjK/nPanBEppcfwyVkNcF0R/dmtyAnxCZd8hXKRAF5t KwR2GpcdHxc9TbmHn3O5wgHnJNDCkESO3dxhFlRjp2//SJS07gkJWZWGHwqxdcLr2vZ+ ugUdcFlWnoos3EwHAXpXtasXG2bCCMr0dxQ+flPKBX5fXHbgxNYb9irQsyanaGaCWdt4 rMdoISyPwPSX6mm2PjeEfXnxB/e9YjAA6waLfdPBBxoDWUQEzX+FzJ4qMYugs2QjPJKL OEOg==
MIME-Version 1.0
X-Received by 10.42.216.148 with SMTP id hi20mr37100826icb.12.1406534285109; Mon, 28 Jul 2014 00:58:05 -0700 (PDT)
In-Reply-To <1406533295.63026.YahooMailNeo@web163804.mail.gq1.yahoo.com>
References <cefbd1ff-b65f-43ec-947e-2324085a6486@googlegroups.com> <53D55ACA.5090901@islandtraining.com> <1406533295.63026.YahooMailNeo@web163804.mail.gq1.yahoo.com>
Date Mon, 28 Jul 2014 17:58:05 +1000
Subject Re: What meaning of this ""hello %s you are %s years old" % x"
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.12384.1406534294.18130.python-list@python.org> (permalink)
Lines 29
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1406534294 news.xs4all.nl 2952 [2001:888:2000:d::a6]:45925
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:75306

Show key headers only | View raw


On Mon, Jul 28, 2014 at 5:41 PM, Albert-Jan Roskam
<fomcl@yahoo.com.dmarc.invalid> wrote:
>> That's not tuple%tuple, but rather string%tuple.  And string%tuple is
>> the older method of formatting an output string from a template and a
>> tuple of values.  See
>> https://docs.python.org/2/library/stdtypes.html#string-formatting for
>> details.
>>
>> However, if you are just learning Python, you should probably use the
>> *newer* formatting operations.  See
>> https://docs.python.org/3.3/library/string.html#formatspec for details
>> of that.
>
> Do you know what was the reason/consideration to switch to a new formatting operation? Ability to have custom formatters with an own __format__ method?

Flexibility. You can do a few things with the other formatting style
that you can't do with percent-formatting. However, percent formatting
isn't going anywhere, and there's no particular reason to avoid it,
even in brand new code. It's more portable across languages (heaps of
C-inspired languages have a printf-style function that responds to the
same notations), more compact, and ample to a lot of situations, so
there's no need to go for the other style.

The only real downside of percent formatting is that, since it's an
operator rather than a function call, it can take only one argument -
so there's some magic with tuples, and a few extremely obscure corner
cases as a result. Not a reason to avoid it.

ChrisA

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


Thread

What meaning of this ""hello %s you are %s years old" % x" fl <rxjwg98@gmail.com> - 2014-07-27 11:49 -0700
  Re: What meaning of this ""hello %s you are %s years old" % x" Gary Herron <gary.herron@islandtraining.com> - 2014-07-27 13:02 -0700
  Re: What meaning of this ""hello %s you are %s years old" % x" Dan Stromberg <drsalists@gmail.com> - 2014-07-27 14:37 -0700
  Re: What meaning of this ""hello %s you are %s years old" % x" Albert-Jan Roskam <fomcl@yahoo.com> - 2014-07-28 00:41 -0700
  Re: What meaning of this ""hello %s you are %s years old" % x" Chris Angelico <rosuav@gmail.com> - 2014-07-28 17:58 +1000

csiph-web