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


Groups > comp.lang.python > #104217

Re: importing

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Tim Golden <mail@timgolden.me.uk>
Newsgroups comp.lang.python
Subject Re: importing
Date Mon, 7 Mar 2016 15:59:57 +0000
Lines 32
Message-ID <mailman.19.1457366406.10335.python-list@python.org> (permalink)
References <56DDA44B.7040405@vanderhoff.org>
Mime-Version 1.0
Content-Type text/plain; charset=windows-1252
Content-Transfer-Encoding 7bit
X-Trace news.uni-berlin.de hwboLHG3x/QSeFrSVWJOlAts/VVJ8/77vz7bAH24liNg==
Return-Path <mail@timgolden.me.uk>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'attributes': 0.07; 'prefix': 0.07; 'imports': 0.09; 'prefixed': 0.09; 'packages.': 0.15; '"*"': 0.16; 'from:addr:timgolden.me.uk': 0.16; 'from:name:tim golden': 0.16; 'message-id:@timgolden.me.uk': 0.16; "module's": 0.16; 'namespace;': 0.16; "package's": 0.16; 'received:74.55.86': 0.16; 'received:74.55.86.74': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'received:smtp.webfaction.com': 0.16; 'received:webfaction.com': 0.16; 'tjg': 0.16; 'tk()': 0.16; 'wrote:': 0.16; 'attribute': 0.18; 'typing': 0.18; "aren't": 0.22; 'correctly.': 0.22; 'space.': 0.22; 'tkinter': 0.22; 'errors': 0.23; 'import': 0.24; 'header:In-Reply-To:1': 0.24; 'module': 0.25; 'header:User- Agent:1': 0.26; 'van': 0.26; 'errors.': 0.27; 'package.': 0.27; "skip:' 10": 0.28; 'implied': 0.29; 'loads': 0.29; 'somebody': 0.30; 'add': 0.34; 'but': 0.36; 'modules': 0.36; 'to:addr:python- list': 0.36; 'subject:: ': 0.37; 'thought': 0.37; 'names': 0.38; 'received:192': 0.39; 'to:addr:python.org': 0.40; 'still': 0.40; 'space': 0.40; 'some': 0.40; 'skip:u 10': 0.61; 'charset:windows-1252': 0.62; 'from:addr:mail': 0.70; 'definitive': 0.84; 'not:': 0.93
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.0.1
In-Reply-To <56DDA44B.7040405@vanderhoff.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.21
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Xref csiph.com comp.lang.python:104217

Show key headers only | 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?
> 

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

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


Thread

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

csiph-web