[Python-Dev] [Python-checkins] cpython: Close #4966: revamp the sequence docs in order to better explain the state of
R. David Murray
rdmurray at bitdance.com
Tue Aug 21 14:01:15 CEST 2012
On 2012年8月21日 17:47:28 +1000, Nick Coghlan <ncoghlan at gmail.com> wrote:
> On Tue, Aug 21, 2012 at 11:55 AM, Ezio Melotti <ezio.melotti at gmail.com> wrote:
> >> +String literals that are part of a single expression and have only
> >> whitespace
> >> +between them will be implicitly converted to a single string literal.
> >> +
> >
> >
> > Is it a string /literal/ they are converted to?
> Yup:
>> >>> ast.dump(compile('"hello world"', '', 'eval', flags=ast.PyCF_ONLY_AST))
> "Expression(body=Str(s='hello world'))"
> >>> ast.dump(compile('"hello" " world"', '', 'eval', flags=ast.PyCF_ONLY_AST))
> "Expression(body=Str(s='hello world'))"
>> > Anyway a simple ('foo' 'bar') == 'foobar' example might make this sentence
> > more understandable.
>> Added.
I think it is an important and subtle point that this happens at "compile
time" rather than "run time". Subtle in that it is not at all obvious
(as this question demonstrates), and important in that it does have
performance implications (even if those are trivial in most cases).
So I think it would be worth saying "implicitly converted to a single
string literal when the source is parsed", or something like that.
--David
More information about the Python-Dev
mailing list