Created
March 5, 2010 14:16
-
-
Save Arachnid/322747 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class LazyRef(object): | |
def __init__(self, fullname): | |
self.fullname = fullname | |
self.ref = None | |
def __call__(self, *args, **kwargs): | |
if not self.ref: | |
modulename, objname = self.fullname.rpartition('.') | |
module = __import__(modulename, globals(), locals()) | |
self.ref = module.__dict__[objname] | |
return self.ref(*args, **kwargs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment