[Python-ideas] Disallow importing the same module under multiple names
Steven D'Aprano
steve at pearwood.info
Wed Mar 14 01:58:28 EDT 2018
On Wed, Mar 14, 2018 at 04:20:20PM +1100, Chris Billington wrote:
> Instead, maybe a user should just get a big fat error if they try to import
> the same file twice under different names.
Absolutely not.
Suppose I import a library, Spam, which does "import numpy".
Now I try to "import numpy as np", and I get an error.
Besides, there is no reason why I shouldn't be able to
import Spam
import Spam as spam
import Spam as Ham
*even in the same script* if I so choose. It's not an error or a mistake
to have multiple names for a single object.
> I wonder if there's any reason something like this shouldn't be built into
> Python's default import system.
Wrong question. The question should not be "Why shouldn't we do this?"
but "why should we do this?".
--
Steve
More information about the Python-ideas
mailing list