What is the Point of General Imports if I Can Just Use Universal Imports?

What is the point of general imports if I can just use universal imports?


Hi @christopherliu654513,

This answer might help: https://discuss.codecademy.com/t/how-is-this-different-from-import-math/338179?u=zystvan

from math import * will let you use the submodules directly, like sqrt(4). import math means you have to call the submodules as part of the math module, like math.sqrt(4).


Both seem to do the same thing. However, the universal import doesn’t require the math. prefix. So, what’s the point of the general import if it does the same thing as the universal import but requires more text?

1 Like

I think that it said that the names could get confusing, or the names of functions and variables could accidentally share a name with something that you import.


Case 1:
The more module you import Universally, the more memory you are using to hold for All the function and variables. Which could end up in a pretty memory heavy program as some libraries have huge amount of functions. So it’s better to use generic or function import of just the specific function you want to use in the program.

Case 2:
A module may have a huge list of functions and variables names and if you import them all they may encounter an error with user-defined function and variable names as they may have the same names.
So that’s why its good practice to just import the desired function from the module.


You could get the functions mixed up if you use universal import. E.g. if you have a sqrt of your own and you import the math functions using universal import, python cannot tell the difference between your sqrt and the imported one.

I also think since there are a lot of functions it could cause some lag.

But, how specific can we be while coding? Let’s say from a general software perspective we can’t say how the updates may arise and that may involve change in import statements to universal and have issues with the variable names. I’m a bit confused here. If possible can you explain