[Python-checkins] r76230 - in python/trunk: Doc/library/functions.rst Lib/test/test_codeop.py Lib/test/test_compile.py Lib/test/test_parser.py Misc/NEWS Parser/parsetok.c Parser/tokenizer.c Parser/tokenizer.h
Nick Coghlan
ncoghlan at gmail.com
Fri Nov 13 23:24:29 CET 2009
Georg Brandl wrote:
> benjamin.peterson schrieb:
>
>> Modified: python/trunk/Doc/library/functions.rst
>> ==============================================================================
>> --- python/trunk/Doc/library/functions.rst (original)
>> +++ python/trunk/Doc/library/functions.rst Fri Nov 13 00:39:44 2009
>> @@ -173,11 +173,10 @@
>>
>> .. note::
>>
>> - When compiling a string with multi-line statements, line endings must be
>> - represented by a single newline character (``'\n'``), and the input must
>> - be terminated by at least one newline character. If line endings are
>> - represented by ``'\r\n'``, use :meth:`str.replace` to change them into
>> - ``'\n'``.
>> + When compiling a string with multi-line statements in ``'single'`` or
>> + ``'eval'`` mode, input must be terminated by at least one newline
>> + character. This is to facilitate detection of incomplete and complete
>> + statements in the :mod:`code` module.
>
> Multi-line statements in "eval" mode?
You can do that with line continuations and bracket matching.
>>>code = compile("sys.stdout.write(str(\n1\n+\n1)+'\\n')\n",
"<string>", "eval")
>>> import sys
>>> exec code
2
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
---------------------------------------------------------------
More information about the Python-checkins
mailing list