Created
November 9, 2012 21:34
-
-
Save saghul/4048405 to your computer and use it in GitHub Desktop.
functools.partial example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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