Whats the difference between importing all the modules in Python 3.x, specific functions in a module and all functions in a module. I know how does it work. But like to understand what advantage do we get while importing a specific function as it no harm when we import all the functions in a module?
Asked
Active
Viewed 34 times
0
-
Possible duplicate of ['import module' or 'from module import'](https://stackoverflow.com/questions/710551/import-module-or-from-module-import) – stochastic13 Feb 26 '18 at 10:50
1 Answers
0
The reason to import specific functions, rather than the entire module, is to avoid a situation where you unintentionally have 2 or more functions with the same name.
This could lead to the program not functioning the way you intend.
You run the risk of this happening particularly with larger, more complex projects.
You can avoid this by importing specific functions. You can also give an alias to the function as you import it:
from module_name import function_name as fn
Then use fn (or whatever alias you have chosen) to call the function.

misterrodger
- 216
- 2
- 8