Re: [Python-Dev] [Python-checkins] cpython: Close #4966: revamp the sequence docs in order to better explain the state of

2012年8月21日 05:03:23 -0700

On 2012年8月21日 17:47:28 +1000, Nick Coghlan <[email protected]> wrote:
> On Tue, Aug 21, 2012 at 11:55 AM, Ezio Melotti <[email protected]> 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
_______________________________________________
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to