Obfuscated Python hack

Gregory Ewing greg.ewing at canterbury.ac.nz
Tue Jun 3 01:40:38 EDT 2014


Tim Chase wrote:
> Stripping off the exec() call makes it pretty transparent that you're
> attempting (successfully on some platforms) to set the value of "4"
> to "5".

But you have to do that in *another* Python session, because
the first one is broken in interesing ways, e.g.

 >>> (lambda *fs: reduce(lambda f, g: lambda x: f(g(x)), fs))(*([lambda s: 
s[1::2]+s[-2::-2]]*54))('motcye;cye._n8fo_drs(d4+)vle=5  ua.8)(isedamr.ticspt 
spt rpi')
   File "<stdin>", line 1
SyntaxError: name 'fs' is local and global

 >>> lambda z: 42
   File "<stdin>", line 1
SyntaxError: name 'z' is local and global

I never knew that error message existed! Is it even possible
to get it from a non-broken Python?

To answer my own question, apparently yes:

 >>> def f(x):
...  global x
...
   File "<stdin>", line 1
SyntaxError: name 'x' is local and global

You learn something every day...

-- 
Greg



More information about the Python-list mailing list