1. 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.
      posted by Ian Bicking at 02:04:09 PM on August 12, 2004  
  2. 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
      posted by John Costello at 03:28:30 PM on August 12, 2004  
  3. 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.
      posted by Michael Hudson at 11:13:39 AM on August 14, 2004  
  4. Argh^2: losing the indentation probably makes it even more obscure! Oh well, you can probably work it out.
      posted by Michael Hudson at 11:14:28 AM on August 14, 2004  
  5. 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)'
      posted by Moof at 05:24:09 AM on August 16, 2004