+ 1

is it even necessary to import just certain objects from a module while you can just simply import the whole module?

python modules

27th Nov 2017, 7:53 AM
Wycliffe Omondi
Wycliffe Omondi - avatar
3 Respuestas
+ 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.
27th Nov 2017, 2:58 PM
Kirk Schafer
Kirk Schafer - avatar
+ 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. 😉
27th Nov 2017, 8:15 AM
blackcat1111
blackcat1111 - avatar
+ 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
27th Nov 2017, 8:00 AM
Pavan Kumar T S
Pavan Kumar T S - avatar