Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #4859
| X-FeedAbuse | http://nntpfeed.proxad.net/abuse.pl feeded by 88.191.16.109 |
|---|---|
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.dougwise.org!nntpfeed.proxad.net!nospam.fr.eu.org!usenet-fr.net!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
| Return-Path | <ian.g.kelly@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.003 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'exception,': 0.07; 'formatting': 0.07; 'python': 0.07; '%s"': 0.09; '3.x': 0.09; 'subject:string': 0.09; 'substituted': 0.09; 'throw': 0.09; 'pm,': 0.11; 'exception': 0.12; 'wrote:': 0.14; '*any*': 0.16; 'str()': 0.16; 'subject:formatting': 0.16; 'wanted.': 0.16; '{0}': 0.16; 'cc:no real name:2**0': 0.20; 'cc:2**0': 0.20; 'code': 0.22; 'header:In-Reply-To:1': 0.22; 'cc:addr:python-list': 0.22; 'skip:{ 10': 0.23; 'possible,': 0.25; 'received:209.85.161.46': 0.26; 'received:mail-fx0-f46.google.com': 0.26; 'instead': 0.26; 'message-id:@mail.gmail.com': 0.28; '"the': 0.28; 'received:209.85.161': 0.29; 'fri,': 0.29; 'number,': 0.29; 'cc:addr:python.org': 0.31; 'construct': 0.31; 'kicks': 0.31; 'entry': 0.32; "skip:' 10": 0.32; "isn't": 0.34; 'clearly': 0.34; 'there': 0.35; 'that,': 0.35; 'should': 0.37; 'received:209.85': 0.37; 'exactly': 0.37; 'received:google.com': 0.38; 'but': 0.38; 'degree': 0.38; 'reasons': 0.38; 'used': 0.38; 'not,': 0.39; 'received:209': 0.39; 'header:Received:5': 0.40; '2011': 0.62; '(3)': 0.64; 'hand,': 0.72; 'print()': 0.84; 'so:': 0.84; 'to:addr:charter.net': 0.84; 'presumably': 0.91 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-type:content-transfer-encoding; bh=rG6DgN8zFnfDnBtsR1yfa6cjM/F6HXaK9Wl10rdJc7w=; b=Ra2Fi3+UB3zw6A89iSSdZgWqcCHQaI0Qbrx88Es2Kz3Flvra7AGR9tdgFiWejnRT5H YfdGAAU2xOXECL1eHYszwX2ECb0EPOZpVb9fnMSr4yWHiuoAJ3X6mZbr4kNSZXMWI9bo wIJgJzqDETFGKdQweFQkmdJ2/15/VNn/0gTvw= |
| DomainKey-Signature | a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; b=smnCNrgya6VGeshIrrjcMiChwLg8So0JheNYLNJpBzUhZKcDstf19kRGnRcBtLLOfQ SLTM7q29S1+JFoDSzZSiB2fcWtws3WHK/JvXj9O9Iqun1F9R3yV401wah1sTbEy8aPC1 vgpRWS7aPA+Es06IuGwNymFyRDT9nYS6l+k4I= |
| MIME-Version | 1.0 |
| In-Reply-To | <D7Ywp.59690$0s5.13933@newsfe17.iad> |
| References | <mailman.1229.1304666321.9059.python-list@python.org> <4dc3aaa0$0$4756$426a74cc@news.free.fr> <4dc3b54c$0$29991$c3e8da3$5496439d@news.astraweb.com> <mailman.1230.1304673808.9059.python-list@python.org> <4dc404b7$0$29991$c3e8da3$5496439d@news.astraweb.com> <RTXwp.18780$Ot6.17862@newsfe15.iad> <D7Ywp.59690$0s5.13933@newsfe17.iad> |
| From | Ian Kelly <ian.g.kelly@gmail.com> |
| Date | Fri, 6 May 2011 13:54:52 -0600 |
| Subject | Re: string formatting |
| To | harrismh777 <harrismh777@charter.net> |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Content-Transfer-Encoding | quoted-printable |
| Cc | python-list@python.org |
| 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.1263.1304711723.9059.python-list@python.org> (permalink) |
| Lines | 34 |
| NNTP-Posting-Host | 82.94.164.166 |
| X-Trace | 1304711724 news.xs4all.nl 81478 [::ffff:82.94.164.166]:55727 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:4859 |
Show key headers only | View raw
On Fri, May 6, 2011 at 1:39 PM, harrismh777 <harrismh777@charter.net> wrote:
> harrismh777 wrote: OP wrote:
>
>> (1) "the %s is %s" % ('sky', 'blue')
>>
>> (2) "the {0} is {1}".format('sky', 'blue')
>>
>> (3) "the {} is {}".format('sky', 'blue')
>
> On the other hand, consider this 3.x code snip:
>
> print("the %s is %d" % ('sky', 'blue'))
>
>
> That formatting will throw an exception, because the format construct is
> restricting the format entry to be a number, which 'blue' clearly isn't....
If you used %d, then that exception is presumably what you wanted. If
not, then you should just do:
print("the %s is %s" % ('sky', 'blue'))
> The following print() is better, because *any* time or *most* types can be
> substituted and the 'polymorphism' of Python kicks in allowing for that, as
> so:
'%s' has exactly the same degree of polymorphism as '{}', because both
simply call str() on their argument. There are good reasons to use
format instead of % if possible, but polymorphism isn't one of them.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
string formatting Jabba Laci <jabba.laci@gmail.com> - 2011-05-06 03:18 -0400
Re: string formatting Web Dreamer <webdreamer@nospam.fr> - 2011-05-06 10:00 +0200
Re: string formatting Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-05-06 08:46 +0000
Re: string formatting Chris Rebert <clp2@rebertia.com> - 2011-05-06 02:23 -0700
Re: string formatting Web Dreamer <webdreamer@nospam.fr> - 2011-05-06 14:10 +0200
Re: string formatting nn <pruebauno@latinmail.com> - 2011-05-06 06:06 -0700
Re: string formatting Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-05-06 14:33 +0000
Re: string formatting Web Dreamer <webdreamer@nospam.fr> - 2011-05-10 16:15 +0200
Re: string formatting Chris Angelico <rosuav@gmail.com> - 2011-05-11 00:43 +1000
Re: string formatting Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-05-06 14:24 +0000
Re: string formatting harrismh777 <harrismh777@charter.net> - 2011-05-06 14:22 -0500
Re: string formatting harrismh777 <harrismh777@charter.net> - 2011-05-06 14:39 -0500
Re: string formatting Ian Kelly <ian.g.kelly@gmail.com> - 2011-05-06 13:54 -0600
Re: string formatting Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-05-07 02:30 +0000
Re: string formatting alex23 <wuwei23@gmail.com> - 2011-05-08 22:47 -0700
Re: string formatting Neil Cerutti <neilc@norwich.edu> - 2011-05-06 19:54 +0000
Re: string formatting Terry Reedy <tjreedy@udel.edu> - 2011-05-06 16:54 -0400
Re: string formatting Chris Angelico <rosuav@gmail.com> - 2011-05-07 10:09 +1000
Re: string formatting Terry Reedy <tjreedy@udel.edu> - 2011-05-07 03:55 -0400
Re: string formatting Raymond Hettinger <python@rcn.com> - 2011-05-10 10:20 -0700
csiph-web