On Wed, Dec 2, 2020 at 2:29 AM Paul Sokolovsky <[email protected]> wrote:
> def fun():
>     # Imports are not allowed at run-time
>     import mod2
>     # But you can re-import module previously imported at import-time.
>     import mod

Wait, what? No. No no no. Please do not do ANYTHING like this. Having
suffered under JavaScript's highly restrictive import system (and
actually been glad for it, since the alternative is far worse), I do
not want ANY version of Python to give up the full power of its import
system, including the ability for a module to be imported only when
it's actually needed. Imports inside functions allow a program to have
optional dependencies, or dependencies that might be slow to load (eg
numpy), and without that, even running your script with "--help" has
to process every single import in the entire file.

-1000.

ChrisA
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/EP24L35CMMDBBYAFVPAP2T4FJNHFRG4T/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to