import X vs from x import *

Tommy Grav tgrav at mac.com
Thu May 22 13:52:37 EDT 2008


On May 22, 2008, at 1:44 PM, notnorwegian at yahoo.se wrote:

> import Tkinter

With this you call functions from Tkinter as

Tkinter.function()

> from Tkinter import *

Here you just call

function()

>
> 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 creates the Tkinter namespace and all of its functions remain
in that namespace. The latter all functions are imported into the local
namespace.

Cheers
   Tommy (actually norwegian)



More information about the Python-list mailing list