What python can NOT do?

Grant Edwards grante at visi.com
Sat Sep 5 05:27:39 CEST 2009

On 2009-09-05, Steven D'Aprano <steve at REMOVE-THIS-cybersource.com.au> wrote:
> On Fri, 04 Sep 2009 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=1\0while x < 5:\0  x+=1\0print 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"


More information about the Python-list mailing list