+ 1

About importing object with 'from'.

Can Any Python boss tell me why when I import only specific objects using 'from module import object', I don't need to use it as 'module.object' ?

27th Jan 2017, 1:23 PM
Reginaldo Junior
Reginaldo Junior - avatar
2 Answers
+ 10
Not a Python boss, but I believe by just importing specific objects which you require from the entire module, it would increase the efficiency of your program, performance wise.
27th Jan 2017, 1:47 PM
Hatsy Rei
Hatsy Rei - avatar
+ 3
http://effbot.org/zone/import-confusion.htm from X import a, b, c imports the module X, and creates references in the current namespace *to the given objects*. Or in other words, you can now use a and b and c in your program. -emphasis mine. (edit didn't stick, trying again) You're creating references to objects inside the module, instead of just for the module itself.
28th Jan 2017, 3:28 PM
Kirk Schafer
Kirk Schafer - avatar