Skip to content

Instantly share code, notes, and snippets.

@saghul
Created November 9, 2012 21:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saghul/4048405 to your computer and use it in GitHub Desktop.
Save saghul/4048405 to your computer and use it in GitHub Desktop.
functools.partial example
from functools import partial
class WorkItem(object):
def __init__(self, func, *args, **kwargs):
self.func = func
self.args = args
self.kwargs = kwargs
def run(self):
try:
return self.func(*self.args, **self.wkargs)
except Exception:
pass
class WorkItemPartial(object):
def __init__(self, func, *args, **kwargs):
self.func = partial(func, *args, **kwargs)
def run(self):
try:
return self.func()
except Exception:
pass
def spam(*args, **kw):
pass
def do_test(klass):
item = klass(spam, 'foo', 1, 'bar', bar='baz')
item.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment