Why use generic import?


#1

I have a question. You can use generic imports to import an entire module, but then you would have to write module_name. in front of every function.
If you don't wish to do that, you can instead choose to use universal import. But why would you then use the generic import?

-Andreas


#2

generic import prevents name conflicts. give you modulename.functionname, there is a very unlikely that it will conflict with another library.

while if you use the universal import on multiply library's, you might have the same function name twice (if you have many library's, and maybe some of your own) this can become a serious problem


#3

Thank you for the quick answer.

This makes sense to me, and it is what i would expect. But it leads me to another question.
When would you then use universal import?


#4

well, if you have just 1 or 2 library's it is very unlikely there are conflicting functions. And then the name is shorter to write.

Also, you could consider just important the function you need, if you just need very little functions from a library:

from x import w,y,z

#5

I see. Thank you for your time and help.

-Andreas