2 ms·
import mpmath.mp as mp Doesn't work in this case because mp isn't a submodule of mpmath. You will get "ModuleNotFoundError: No module named 'mpmath.mp'" The "
by fluidcruft 3y ago
import mpmath.mp as mp
Doesn't work in this case because mp isn't a submodule of mpmath. You will get "ModuleNotFoundError: No module named 'mpmath.mp'"
The "from" is what dives into a module and takes something out. It's not just defining a syntactic macro. You would have to do something closer to this:
import mpmath
mp = mpmath.mp
del mpmath
to replace what "from" does.
- PurpleRamen 3y agoThat's an implementation-detail. Nothing prevents the import from diving automatically into the file. But doing so would open the door for name-shadowing, as with a package you could have a separate mp.py for import, or a definition of mp in __init__.py. And this would be another confusion for people, and a performance-problem maybe.