[Python-ideas] lazy use for optional import

Berker Peksağ berker.peksag at gmail.com
Wed Mar 1 05:49:15 EST 2017


On Wed, Mar 1, 2017 at 2:31 AM, Nicolas Cellier
<contact at nicolas-cellier.net> wrote:
> For example:
>
>> lazy import pylab as pl  # do nothing for now
>>
>> # do stuff
>>
>> def plot(*args):
>>     pl.figure() # Will raise an ImportError at this point
>>     pl.plot(...)

This can already be achieved without introducing a new keyword by
using LazyLoader:
https://docs.python.org/3/library/importlib.html#importlib.util.LazyLoader

--Berker


More information about the Python-ideas mailing list