[Tutor] Confused "from module import Name" better than "import module"?
Mike Hansen
mhansen at cso.atmel.com
Mon Jul 11 18:12:51 CEST 2005
I'm confused. I was just reading the URL below..
http://jaynes.colorado.edu/PythonGuidelines.html
and this statement confused me: "Always use from module import Name, Name2,
Name3.. syntax instead of import module or from module import *. This is more
efficient, reduces typing in the rest of the code, and it makes it much easier
to see name collisions and to replace implementations."
To me, import module is more explicit.
It seems to easier to read CoolModule.niceFunction() than just niceFunction().
You know exactly where niceFunction comes from especially when you've imported
many modules. Don't you avoid namespace pollution too by using import module
instead of from module import * or from module import Name, Name2, Name3...?
What is the preferred/better way to import modules?
Mike
More information about the Tutor
mailing list