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


Groups > comp.lang.python > #104217 > unrolled thread

Re: importing

Started byTim Golden <mail@timgolden.me.uk>
First post2016-03-07 15:59 +0000
Last post2016-03-07 15:59 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: importing Tim Golden <mail@timgolden.me.uk> - 2016-03-07 15:59 +0000

#104217 — Re: importing

FromTim Golden <mail@timgolden.me.uk>
Date2016-03-07 15:59 +0000
SubjectRe: importing
Message-ID<mailman.19.1457366406.10335.python-list@python.org>
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?
> 

What you're seeing is that "messagebox" is a module inside the "tkinter"
package. And modules are not automatically made available under their
parent packages.

That is: a module's attributes are part of its namespace; but a
package's modules aren't part of its.

TJG

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web