import X vs from x import *

inhahe inhahe at gmail.com
Thu May 22 13:48:29 EDT 2008


<notnorwegian at yahoo.se> wrote in message 
news:c8ca75c3-98ab-4c74-8868-b58fbc12a0b2 at m73g2000hsh.googlegroups.com...
> import Tkinter
> from Tkinter import *
>
> i have a program where if i comment out either of those import-
> statements i get an error.
>
> i thought they meant the same thing and from was supposed to be just
> to imort just a specific function and the * imports everything in the
> module.
> but aparently the above statements have diffrent meaning and i cant
> figure it out fromt he tutorials.

the first statement imports tkinter but everything inside of tkinter in 
stored in the tkinter namespace, in other words
if tkinter has a class tk, then tk would be accessed as tkinter.tk. for 
example
import tkinter
blah = tkinter.tk()
if you do from tkinter import *, then everything in tkinter is imported at 
the top level, so it would be
from tkinter import *
blah = tk()







More information about the Python-list mailing list