+ 1
is it even necessary to import just certain objects from a module while you can just simply import the whole module?
python modules
3 odpowiedzi
+ 3
Note ...
"...the module is always fully imported ... the only difference ... is what name is bound..."
https://softwareengineering.stackexchange.com/questions/187403/import-module-vs-from-module-import-function/187471
...so "namespacing" and (trivially noted) whether the imported item ends up in your default help documentation.
Breaks down the whole system:
http://effbot.org/zone/import-confusion.htm
Recommends "Always use import..."
It is almost universally agreed that "from ... import *" is a bad idea because it's hard to determine what's in use.
* You mention Python twice so I chose that; your c++ and Java keywords have different build plans.
+ 5
Up to you, but it kind of depends on how much of the module you are going to use. Importing the whole math module just to use math.sqrt could be quite unnecessary, and waste precious memory space. So, really up to you, and what you want to do. 😉
+ 1
it's preferred to import required part of library than importing lib itself because it reduces your program memory. although it's upto developer to choose