Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #104218
| From | Ian Kelly <ian.g.kelly@gmail.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: importing |
| Date | 2016-03-07 09:02 -0700 |
| Message-ID | <mailman.20.1457366601.10335.python-list@python.org> (permalink) |
| References | <56DDA44B.7040405@vanderhoff.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.
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: importing Ian Kelly <ian.g.kelly@gmail.com> - 2016-03-07 09:02 -0700
csiph-web