Skip to content

Instantly share code, notes, and snippets.

@tswicegood
Created February 9, 2010 15:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save tswicegood/299338 to your computer and use it in GitHub Desktop.
Save tswicegood/299338 to your computer and use it in GitHub Desktop.
from functools import wraps
def objectify(func):
expected_prefixes = ("with", "for", "and", "or")
@wraps(func)
def objectified_func(*args, **kwargs):
real_kwargs = {}
for k, v in kwargs.items():
try:
if k[0:k.index("_")] in expected_prefixes:
k = k[k.index("_")+1:]
except ValueError, e:
print "error: %s" % e
real_kwargs[k] = v
return func(*args, **real_kwargs)
return objectified_func
@objectify
def print_name(user):
print "name is %s" % user
print_name(for_user="Travis Swicegood")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment