Tkinter + import question

Andreas Kostyrka andreas at mtg.co.at
Mon Apr 8 16:35:56 EDT 2002


On Sun, 31 Mar 2002 13:09:58 -0500
"Adonis Vargas" <deltapigz at telocity.com> wrote:

> i am writting a program utilizing Tk as my gui engine, and i have broken
> down sections of the form into modules and loaded them through a main
> script. my only question is in every module i am forced to import the
> Tkinter module, and does this pose consume too much memory? or does python
Nope.
Importing in Python consists of two "steps":
1.) load the .pyc or .so (.dll) file.
2.) add it to the namespace of the modules that does the import.

The first step is done only once, so later imports are quite fast and do not consume memory (well they do for the dictionary entry in the second module, but this is negliable.)

Actually one can get the effect you want to have like this: (DO NOT USE THIS UNLESS YOU KNOW WHAT YOU DO)
import __builtins__
import Tkinter
__builtins__.Tkinter=Tkinter

This makes Tkinter a "builtin" symbol that is visible in all modules.

Andreas





More information about the Python-list mailing list