Re: Defer, ensure library is loaded

2018-02-13 Thread Steven D'Aprano
On Tue, 13 Feb 2018 08:02:38 -0800, Jason wrote: > I have a variety of scripts that import some large libraries, and rather > than create a million little scripts with specific imports, I'd like to > so something like > > psycopg2 = ensure_imported (psycopg2) > > This way, regardless of

Re: Defer, ensure library is loaded

2018-02-13 Thread Steven D'Aprano
On Wed, 14 Feb 2018 03:08:07 +1100, Chris Angelico wrote: [...] > import psycopg2 > > If it's already been imported, Python will go fetch it straight from the > cache, so it's fast. Since Jason is talking about "a variety of scripts", it is quite possible that the sys.modules cache will not

Re: Defer, ensure library is loaded

2018-02-13 Thread Chris Angelico
On Wed, Feb 14, 2018 at 3:02 AM, Jason wrote: > I have a variety of scripts that import some large libraries, and rather than > create a million little scripts with specific imports, I'd like to so > something like > > psycopg2 = ensure_imported (psycopg2) > > This way,

Defer, ensure library is loaded

2018-02-13 Thread Jason
I have a variety of scripts that import some large libraries, and rather than create a million little scripts with specific imports, I'd like to so something like psycopg2 = ensure_imported (psycopg2) This way, regardless of invocation I can know psycopg2 is loaded, if it hasn't already been