Comment by mywittyname
8 years 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-h...
I have, and it actually works well (performance wise). The maintenance burden is a little higher.
A 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.
3.7 makes it easier to use dynamic imports. https://snarky.ca/lazy-importing-in-python-3-7/