Skip to content

Instantly share code, notes, and snippets.

@leegao
Created March 4, 2010 03:57
Show Gist options
  • Select an option

  • Save leegao/321384 to your computer and use it in GitHub Desktop.

Select an option

Save leegao/321384 to your computer and use it in GitHub Desktop.
#Hello World
class Operator(object):
def __init__(self, func, count=2):
self._func_ = func
self._args_ = []
self._count_ = count
def __ror__(self, first_arg):
self._args_.append(first_arg)
return self
def __or__(self, arg):
self._args_.append(arg)
if len(self._args_) >= self._count_:
return self(*self._args_)
else:
raise RuntimeError("Incorrect number of parameters")
def __call__(self, *args, **kwargs):
self._args_ = []
return self._func_(*args, **kwargs)
def alpha(letter):
@Operator
def _alpha(a,b):
return a+letter+b
return _alpha
for c in range(65, 122):
globals()[chr(c)] = alpha(chr(c))
print "H"|e|"l"|l|"o","W"|o|"r"|l|"d"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment