On Tuesday, August 2, 2016 at 3:32:11 AM UTC+12, Ganesh Pal wrote:
> is it a good programming practice to use import * ?
No. Think of the module you’re importing as a can, and each of the names it
defines as a worm. So you when you do “from «module» import *”, it’s like
emptying all the worms in the can onto the floor, and letting them crawl all
over your program, polluting your global namespace.
Now imagine you change your mind, and want to get all the worms back into the
can, because people reading your program (yourself included) cannot be sure
where each name is coming from.
Not a pleasant process. So the wise programmer avoids getting into this
situation.
Yes, it can be annoying to have to write module names over and over. Python
lets you use alternative names, e.g.
import long_module_name as lmn
then you say “lmn.«name»” instead of “long_module_name.«name»”.
--
https://mail.python.org/mailman/listinfo/python-list