Relative-importing *

Bruno Desthuilliers bdesth.quelquechose at free.quelquepart.fr
Wed Jul 25 15:15:53 EDT 2007


Steven D'Aprano a écrit :
(snip)
> I do take your point that importing * has the potential to unexpectedly
> clobber names you didn't intend,

Another problem is that it makes harder to know from which module a name 
comes from.

> and that's a good reason to avoid it
> unless you have a good reason to use it. But there are good reasons.
> 
> The "from module import *" statement is very useful if you wish to export
> all the public objects from a "private" module, e.g. emulate what the os
> module does with platform specific functions.

Indeed.

(snip)

> I certainly agree that "from module import *" is easily abused, but to go
> from there to the conclusion that it is a blight that must be stamped out
> is far too strong.

As with any "you shall not..." programming rule (goto's, multiple return 
points, public attributes, etc, etc), it stands as long as you don't 
fully understand when and why it's ok to do it.




More information about the Python-list mailing list