Occasionally I want lazy module loading in Python. Usually because I want to keep runtime requirements or start-up times low and splitting the code into sub-modules would be cum
class Handler(...): ... def render_with_jinja2(self, values, template_name): import jinja2 env = jinja2.Environment(...) ...
There's no need to cache the imported module; Python does that already.