Skip to content

Instantly share code, notes, and snippets.

@RonnyPfannschmidt
Created January 23, 2017 16:30
Show Gist options
  • Save RonnyPfannschmidt/f7051504cde67689b5ba10b1745aedaa to your computer and use it in GitHub Desktop.
Save RonnyPfannschmidt/f7051504cde67689b5ba10b1745aedaa to your computer and use it in GitHub Desktop.
import attr
import importlib
from operator import attrgetter
@attr.s
class DefferedImport(object):
module = attr.ib()
attribute = attr.ib(default=None)
def __get__(self, instance, owner):
module = importlib.import_module(self.module)
if self.attribute is None:
return module
else:
return getattr(module, self.attribute)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment