What python can NOT do?
Grant Edwards
grante at visi.com
Fri Sep 4 23:27:39 EDT 2009
On 2009年09月05日, Steven D'Aprano <steve at REMOVE-THIS-cybersource.com.au> wrote:
> On 2009年9月04日 08:21:15 -0700, Mike Coleman wrote:
>>> It is true, though, that Python
>> cannot be used to write arbitrarily complex one-liners, though.
>> Incorrect.
>>>>> exec "x=10円while x < 5:0円 x+=10円print x".replace('0円','\n')
> 5
>> Take (almost) any arbitrary piece of Python code. Replace all newlines by
> nulls. Escape any quotation marks. Wrap the whole thing in quotes, and
> pass it to exec as above, and you have an arbitrarily complex one-liner.
I don't understand the reason for the newline/null swapping.
Why not just do this?
>>> exec "x=1\nwhile x < 5:\n x+=1\nprint x\n"
5
--
Grant
More information about the Python-list
mailing list