3 ms·
Have you tried moving import statements into the functions where they are invoked? My understanding is this is effectively the same as lazy loading the module[
by mywittyname 9y ago
Have you tried moving import statements into the functions where they are invoked? My understanding is this is effectively the same as lazy loading the module[1].
[1] https://stackoverflow.com/questions/3095071/in-python-what-happens-when-you-import-inside-of-a-function https://stackoverflow.com/questions/3095071/in-python-what-h...
- cjhanks 9y agoI have, and it actually works well (performance wise). The maintenance burden is a little higher.
- sli 9y agoA little Python preprocessor that lets you annotate your lazy modules sounds like a fun little toy project, actually. Not something I'd use for real, but it would be fun to build.
- jsmeaton 9y ago3.7 makes it easier to use dynamic imports. https://snarky.ca/lazy-importing-in-python-3-7/ https://snarky.ca/lazy-importing-in-python-3-7/