Created
June 17, 2015 13:27
-
-
Save BasicWolf/a735eb061cb4efc60f04 to your computer and use it in GitHub Desktop.
Cache data and pass it to a method
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 wraps | |
def cache(**cached_kwargs): | |
def wrap(f): | |
@wraps(f) | |
def wrapped(self, *args, **kwargs): | |
kwargs.update(cached_kwargs) | |
return f(self, *args, **kwargs) | |
return wrapped | |
return wrap | |
class C: | |
names = ['Alex', 'Laura', 'John', 'Mia'] | |
@cache(a_names=[name for name in names if name.startswith('A')] | |
def get_names_startwith_a(self, a_names): | |
return a_names |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment