Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #104224

Re: importing

From Mark Lawrence <breamoreboy@yahoo.co.uk>
Newsgroups comp.lang.python
Subject Re: importing
Date 2016-03-07 16:28 +0000
Message-ID <mailman.26.1457368166.10335.python-list@python.org> (permalink)
References <56DDA44B.7040405@vanderhoff.org>

Show all headers | View raw


On 07/03/2016 15:54, Tony van der Hoff wrote:
> I thought I understood this, but apparently not:
> Under py3:
>
> 1. "import tkinter" imports the whole module into the name space. Any
> access to names therein must be prefixed with the module name.
> ie top = tkinter.Tk()
> But tkinter.messagebox.showwarning()  errors with "module has no
> attribute 'messagebox'"
>
> 2. "from tkinter import *" loads the name space from the module into the
> program name space. No need to prefix the module name onto the attribute
> name. Pollutes the name space, but makes typing easier.
> ie top = Tk()
> But messagebox.showwarning() still errors.
>
> 3. in either of the above cases, if I add "from tkinter import
> messagebox, the attribute resolves correctly.
>
> I imagined that the "*" form implied "load the lot". Evidently, my
> understanding is lacking. Will somebody please put me straight, or give
> me a reference to some definitive documentation?
>

As a slight aside, and as you've all ready had answers, you might like 
to read the Bryan Oakley response to this 
http://stackoverflow.com/questions/17466561/best-way-to-structure-a-tkinter-application

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: importing Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-03-07 16:28 +0000

csiph-web