[Python-ideas] New use for the 'in' keyword.
Jonathan Fine
jfine2358 at gmail.com
Mon Mar 11 06:27:29 EDT 2019
Hi Simon
You've suggested allowing
import numpy as np
import math in np
as an improvement on
from somewhere import *
But you can get a similar result already, by writing in your package
import .aaa as np
and within mypackage/aaa.py writing
from numpy import *
from math import *
When you write
import numpy as np
the value of the identifier becomes the numpy module. Your proposal
aims to add to that module additional key-value pairs. (A module is a
bit like a dict.) And perhaps clobber some existing resources.
It's generally best to treat a module as a read-only object. That way,
you don't get side-effects. This is why Chris was talking about
monkey-patching.
--
Jonathan
More information about the Python-ideas
mailing list