-
type() is fun too. type(x) returns the type of x. type('a', b, {}) returns class a(b): pass (more or less).
This doesn't do anything interesting, but it is confusing: v = type('', (), {'next': type('', (), {'__get__': lambda v, o, s: s()})(), '__repr__': lambda s: sys.modules.keys()[id(s)%len(sys.modules.keys())]})()
Merely confusing isn't very interesting, though. It's much better if it does something useful.
-
Use functions from itertools such as imap and izip as well as list constructors to really confuse the issue. Oh, yeah, and lambda functions.
from itertools import izip, imap
def ptiter(filenames):
for r, row in enumerate(
imap(lambda l: izip(*[l[n] for n in range(len(filenames))]),
izip(*[imap(lambda l: imap(float, l.split()),
file(filename))
for filename in filenames]))):
for c, data in enumerate(row):
yield [c, r] + data
-
Argh. As this post is I guess at least somewhat my fault, I really should supply something especially horrible, but a truly obfuscated piece of code takes more time and effort than I really want to spend now.
Here's a short abuse of new-style classes for yout entertainment, though:
class C(object):
def __int__(self):
return ord(getattr(self, '__name__', '\00')[0])
__get__ = range
print type('', (type, C), {})('\002', (int,), {'c':C()})(10).c
Samuele Pedroni should take some of the credit/blame for this one.
-
Argh^2: losing the indentation probably makes it even more obscure! Oh well, you can probably work it out.
-
You don't have to work hard to be too obscure in intent. From a previous .sig of mine:
python -c 'l = (("asynchat", 653, 658), ("httplib", 162, 170), ("pickle", 46, 53),("sched", 145, 149), ("re", 32, 35)); w=[__import__(x[0]).__doc__[x[1]:x[2]] for x in l]; w[3] += w.pop(); print "".join(w)'