[Tutor] Confused "from module import Name" better than "importmodule"?

Alan G alan.gauld at freenet.co.uk
Mon Jul 11 22:06:52 CEST 2005


> I'm confused. I was just reading the URL below..
>
> http://jaynes.colorado.edu/PythonGuidelines.html

Me too. :-)

> 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."

The efficiency gain is negligible.
The typing can be better reduced by using

import modulename as m

And it definitley doesn't make it easier to see name collisions, they 
will
just silently collide and one or the other name will be hidden with
strange results!

> To me, import module is more explicit.

Undeniably so!

> It seems to easier to read CoolModule.niceFunction() than just 
> niceFunction().

Easier to read but slightly harder to type. Personally I can live with 
it!

Alan G. 



More information about the Tutor mailing list