Why Lazy Import is not default in Python?

python

Solution

Here's an example of lazy import in python:

def xmlfrobnicator(xmlstr):
    from lxml import etree

    # do whatever

It's not commonly used because it offers very few advantages for most programmes - once loaded, the module is loaded (unless you take steps to unload it), and it's pretty rare to have a dependency that is used so infrequently that only loading it when in use is worthwhile.

I think you may have been looking at javascript, where programmes may only run for a short time, and not use all of their features, and even if they do, background loading of modules improves user-perceived speed.

Problem

I am trying to understand few things with respect to design. I see a number of the code where Lazy Import features is used.By Lazy Import, I mean a facility provided by certain recipes, packages and modules which support "LazyImport" style. Those implementation in general aim to import the module only when it is used and provide some extra hooks for different things. I know there the error condition is delayed over here, but I am trying to understand why Lazy Import is not a default strategy in Python. What could it's (other) drawbacks be which prevent it from making a general useful case. Or are there languages which use this as a default import mechanism strategy.

Original source