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


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

Re: importing

Started byIan Kelly <ian.g.kelly@gmail.com>
First post2016-03-07 09:02 -0700
Last post2016-03-07 09:02 -0700
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 Ian Kelly <ian.g.kelly@gmail.com> - 2016-03-07 09:02 -0700

#104218 — Re: importing

FromIan Kelly <ian.g.kelly@gmail.com>
Date2016-03-07 09:02 -0700
SubjectRe: importing
Message-ID<mailman.20.1457366601.10335.python-list@python.org>
On Mon, Mar 7, 2016 at 8:54 AM, Tony van der Hoff <tony@vanderhoff.org> 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'"

tkinter.messagebox is a module inside the tkinter package. Importing
tkinter doesn't automatically import tkinter.messagebox also.

>
> 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.

This is still just loading names from the tkinter module, not its submodules.

> 3. in either of the above cases, if I add "from tkinter import messagebox,
> the attribute resolves correctly.

This is the first place where you actually instruct Python to import
tkinter.messagebox.

[toc] | [standalone]


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


csiph-web