[Tutor] "from this import *" or "import this"
Sun, 2 Dec 2001 14:06:54 -0800 (PST)
On Sun, 2 Dec 2001, Jean Montambeault wrote:
> Be ready for a whole lot of very newbie questions. I've never
> programmed before and do not intend to make a career out of what I am
> learning : pure amateurism here which does not necessarily implies
> triviality but that shouldn't be a surprise.
Very true. Welcome aboard!
> is there a real use for the form "from this_module import * "
> (a) there seems to be a real danger to get some functions or
> variables which would have the same name if more than one module are
> open that way
> (b) nothing shows the relation to the module which is to
> some extent documenting the program
> (c) it imports the whole module (I guess) just as "import
> this_module" seems to be doing
Yes; you've just listed all the reasons why 'from this_module import *' is
heavily frowned upon. *grin* Good observations.
> Or is it much safer and wiser to avoid using it ?
It's usually safer to avoid it. It's convenient because one doesn't need
to type in the module name, so there's less typing. On the other hand,
there are all those disadvantages that you've listed.
There are special situations where it's useful, particularly in Tkinter
GUI programming. In that case, the designers of Tkinter kept as a design
goal that 'from Tkinter import *" should be safe. In general, though,
'from this_module import *' is not a good idea.