PythonSyntax

Last edit December 10, 2009
PythonSyntax works for me because of :

  • lack of braces - I often forget them or lose them in other languages
  • smallest amount of typing - many other languages seem verbose to me
  • whitespace - indentation as block delimiting makes it easy for me to read.

  • Really intuitive syntax for returning multiple objects from a function.

  • Array slice notation (yes we know Python wasn't the first)

I don't suppose that there is any chance of an ObfuscatedPython Contest, is there?

  • Actually, there is, but it mostly involves lambdas and using both tabs and spaces.

Mmm... who can guess what the following code prints?

  print (lambda x:"print %s(%s)"%(x,repr(x)))('(lambda x:"print %s(%s)"%(x,repr(x)))')
Neat, but not surprising. I like this old one from TimPeters

 a=range(1,11);(eval('a.'+[].__methods__[-2])()or a)

Just how old would that be? '__methods__' appears not to exist in Python 2.3...

Maybe the following works in newer Python:

 a=range(1,11);(eval('a.'+dir([])[-2])()or a)

and of course ...

 #!/usr/local/bin/python -- -export-a-crypto-system-sig -RSA-in-4-lines-Python
 from sys import*;a=argv;[s,p,q]=filter(lambda x:x[:1]!=
 '-',a);d='-d'in a;e,n=long(p,16),long(q,16);l=(len(q)+1)/2;o,inb=l-d,l-1+d
 while s:s=stdin.read(inb);s and map(stdout.write,map(lambda i,b=pow(reduce(
 lambda x,y:(x<<8L)+y,map(ord,s)),e,n):chr(b>>8*i&255),range(o-1,-1,-1)))
Wear that on a t-shirt in asia and you're stylin'!

Oops, is this wiki now a munition?

Nah, they relaxed the export prohibitions.
See PythonWhiteSpaceDiscussion, PythonVsRuby