Skip to content

Instantly share code, notes, and snippets.

@codeinthehole
Created September 9, 2011 08:38
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codeinthehole/1205776 to your computer and use it in GitHub Desktop.
Save codeinthehole/1205776 to your computer and use it in GitHub Desktop.
Lightweight subclassing using curry
def curry(f, *args, **kwargs):
def curried(*more_args, **more_kwargs):
return f(*(args+more_args), **dict(kwargs, **more_kwargs))
return curried
class Person(object):
def __init__(self, name, gender):
self.name = name
self.gender = gender
# Lightweight subclasses
Man = curry(Person, gender="Male")
Woman = curry(Person, gender="Female")
husband = Man("Donald")
wife = Woman("Donalina")
print husband.name, wife.name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment