On Sat, 28 Mar 2026 at 14:13, DFS via Python-list <[email protected]> wrote: > > On 3/25/2026 9:40 PM, Lawrence D’Oliveiro wrote: > > > So Python 3.15 will introduce a new, “lazy” import mechanism > > <https://peps.python.org/pep-0810/>. > > > > So far I have done one script where I moved an import into the > > function where it was used, instead of doing it globally; this reduced > > the script startup time from around 1.5 seconds down to about a > > quarter second. > > > > “Lazy” imports would avoid the need for such workarounds, while > > keeping all imports together so they can be found more easily. > > > Faster startup is nice, but lazy importing doesn't reduce total runtime > of the program, right?
If the things that were lazily imported never get used then the program can complete without those things ever being fully imported. Think of the runtime for something like: python myscript.py --help That script could import all sorts of slow loading libraries but probably does not need to use any of them just to display the --help output. -- Oscar -- https://mail.python.org/mailman3//lists/python-list.python.org
