from Tkinter import *
Matthew Dixon Cowles
matt at mondoinfo.com
Tue Mar 6 19:34:15 EST 2001
On Tue, 6 Mar 2001 15:16:31 -0800, Timothy Grant
<tjg at exceptionalminds.com> wrote:
> All of Fredrik's examples in his guide on Tkinter use
>from Tkinter import *
>Now, I'm aware that the effbot is never wrong about anything<wink>,
>but is it safe to assume that I should not be using the above idiom,
>but the import Tkinter idiom instead?
Rest assured, the effbot is right as usual.
There are really two things going on with "from foo import *": The
first is that under some circumstances doing it at other than module
scope (e.g. in a function or method) is eventually going to become
illegal. That's unlikely to be a problem for very many people since
"from Tkinter import *" is almost always at the left margin.
The second reason someone might not want to do "from foo import *" is
that it's possible to cause surprises by importing a name that shadows
something important. If my module foo defines foo.open and I do "from
foo import *", I may get surprising results the next time I try to
open a file. Tkinter's names are chosen to make that sort of problem
unlikely.
Everyone assumes that everyone does "from Tkinter import *" and I
don't think that anyone is going to make it a bad idea any time soon.
Regards,
Matt
More information about the Python-list
mailing list