Skip to content

Instantly share code, notes, and snippets.

@Arachnid
Created March 5, 2010 14:16
Show Gist options
  • Save Arachnid/322747 to your computer and use it in GitHub Desktop.
Save Arachnid/322747 to your computer and use it in GitHub Desktop.
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