Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #89557
| Path | csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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; ';-)': 0.03; 'subject:not': 0.03; 'from:addr:yahoo.co.uk': 0.04; 'syntax': 0.04; 'important,': 0.07; 'string': 0.09; 'cest': 0.09; 'lawrence': 0.09; 'method:': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'language.': 0.14; "'to": 0.16; 'adjacent': 0.16; 'concatenate': 0.16; 'expression,': 0.16; 'literal,': 0.16; 'literal.': 0.16; 'literals': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:format': 0.16; 'syntaxerror:': 0.16; '{0}': 0.16; 'language': 0.16; 'wrote:': 0.18; 'work,': 0.20; '>>>': 0.22; 'print': 0.22; 'header:User- Agent:1': 0.23; 'wednesday': 0.24; 'second': 0.26; 'header:X -Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'wondering': 0.29; 'am,': 0.29; "skip:' 10": 0.31; 'could': 0.34; 'subject:with': 0.35; 'one,': 0.35; 'but': 0.35; 'method': 0.36; 'skip:. 20': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'either': 0.39; 'received:org': 0.40; 'called': 0.40; 'dave': 0.60; 'first': 0.61; "you've": 0.63; 'our': 0.64; 'worth': 0.66; 'determine': 0.67; 'invalid': 0.68; '2015': 0.84; 'received:2': 0.84 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
| Subject | Re: implicitly concats of adjacent strings does not work with format |
| Date | Wed, 29 Apr 2015 17:04:49 +0100 |
| References | <877fsvcdhz.fsf@Equus.decebal.nl> <mailman.86.1430313312.3680.python-list@python.org> <87383jc80w.fsf@Equus.decebal.nl> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8; format=flowed |
| Content-Transfer-Encoding | 8bit |
| X-Gmane-NNTP-Posting-Host | host-2-98-195-171.as13285.net |
| User-Agent | Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 |
| In-Reply-To | <87383jc80w.fsf@Equus.decebal.nl> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.20+ |
| 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.87.1430323506.3680.python-list@python.org> (permalink) |
| Lines | 67 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1430323506 news.xs4all.nl 2919 [2001:888:2000:d::a6]:59225 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:89557 |
Show key headers only | View raw
On 29/04/2015 15:40, Cecil Westerhof wrote:
> Op Wednesday 29 Apr 2015 15:14 CEST schreef Dave Angel:
>
>> On 04/29/2015 08:42 AM, Cecil Westerhof wrote:
>>> I have the folowing print statements:
>>> print(
>>> 'Calculating fibonacci_old, fibonacci_memoize and'
>>> 'fibonacci_memoize once for {0} '.format(large_fibonacci))
>>>
>>>
>>> print(
>>> 'Calculating fibonacci_old, fibonacci_memoize and'
>>> 'fibonacci_memoize once for {0} '.format(large_fibonacci) +
>>> 'to determine speed increase')
>>>
>>> print(
>>> 'Calculating fibonacci_old, fibonacci_memoize and'
>>> 'to determine speed increase'
>>> 'fibonacci_memoize once for {0} '.format(large_fibonacci))
>>>
>>>
>>> print(
>>> 'Calculating fibonacci_old, fibonacci_memoize and'
>>> 'fibonacci_memoize once for {0} '.format(large_fibonacci)
>>> 'to determine speed increase')
>>>
>>> The first three work, but the last gives:
>>> 'to determine speed increase')
>>> ^
>>> SyntaxError: invalid syntax
>>>
>>> Not very important, because I can use the second one, but I was
>>> just wondering why it goes wrong.
>>>
>>
>> Adjacent string literals are concatenated. But once you've called a
>> method (.format()) on that literal, you now have an expression, not
>> a string literal.
>>
>> You could either change the last line to
>>
>> + 'to determine speed increase')
>>
>> or you could concatenate all the strings before calling the format
>> method:
>>
>>
>> print(
>> 'Calculating fibonacci_old, fibonacci_memoize and'
>> 'fibonacci_memoize once for {0}'
>> 'to determine speed increase' .format(large_fibonacci))
>
> I now use this, I did not know that the addjacent-concatenation
> occurred at compile time.
> I spend a ‘little‘ time, but it was worth it.
>
> From the amount of messages you could think I am a spammer. ;-)
>
Did you mean spanner? ;-)
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.
Mark Lawrence
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
implicitly concats of adjacent strings does not work with format Cecil Westerhof <Cecil@decebal.nl> - 2015-04-29 14:42 +0200
Re: implicitly concats of adjacent strings does not work with format Dave Angel <davea@davea.name> - 2015-04-29 09:14 -0400
Re: implicitly concats of adjacent strings does not work with format Cecil Westerhof <Cecil@decebal.nl> - 2015-04-29 16:40 +0200
Re: implicitly concats of adjacent strings does not work with format Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-04-29 17:04 +0100
Re: implicitly concats of adjacent strings does not work with format Cecil Westerhof <Cecil@decebal.nl> - 2015-04-29 19:08 +0200
Re: implicitly concats of adjacent strings does not work with format Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-04-29 21:51 +0100
Re: implicitly concats of adjacent strings does not work with format Cecil Westerhof <Cecil@decebal.nl> - 2015-04-29 23:51 +0200
csiph-web