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


Groups > comp.lang.python > #104218

Re: importing

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Ian Kelly <ian.g.kelly@gmail.com>
Newsgroups comp.lang.python
Subject Re: importing
Date Mon, 7 Mar 2016 09:02:33 -0700
Lines 27
Message-ID <mailman.20.1457366601.10335.python-list@python.org> (permalink)
References <56DDA44B.7040405@vanderhoff.org>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
X-Trace news.uni-berlin.de aymRtBYNeJ+RIWOJKXUHyg10VckJqMlju32rkdz/mDYQ==
Return-Path <ian.g.kelly@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.006
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'prefix': 0.07; 'imports': 0.09; 'prefixed': 0.09; 'python': 0.10; 'importing': 0.15; '2016': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'tk()': 0.16; 'wrote:': 0.16; 'attribute': 0.18; 'module,': 0.18; 'typing': 0.18; 'correctly.': 0.22; 'space.': 0.22; 'tkinter': 0.22; 'am,': 0.23; 'errors': 0.23; 'import': 0.24; 'header:In-Reply-To:1': 0.24; 'mon,': 0.24; 'module': 0.25; "doesn't": 0.26; 'van': 0.26; 'message-id:@mail.gmail.com': 0.27; 'errors.': 0.27; 'package.': 0.27; "skip:' 10": 0.28; 'loads': 0.29; 'loading': 0.33; 'add': 0.34; 'received:google.com': 0.35; 'but': 0.36; 'received:209.85': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:209.85.213': 0.37; 'thought': 0.37; 'received:209': 0.38; 'names': 0.38; 'to:addr:python.org': 0.40; 'where': 0.40; 'still': 0.40; 'space': 0.40; 'mar': 0.65; 'to:name:python': 0.84; 'not:': 0.93
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=6TFn5UsPaFw5NkvR0Clh1WjzdmcVyuknQ2AwIqdZHbU=; b=AJKo1jGCFo7bh8WRQWDhN9KquXBLXywPlzeCxzvvAfJq2FtSm5tZXp5WJ0Bw6OhXWv 6Eh4bdYxkbM/7/6orFhhj8rbRWiiwA2KAY99lKhw6B0ZfXs87N0ne68PeMNPmex0jrYS Be+PzSCQYJEiEHLJDgYfTO658FKLh0D2dMYZ/SdshyPX5hmj39Jb7eOKlKjoG4Utj+up UENUPH09dJa7NIAJijYxbpAFiV3l8zGkkjHSBu/FvsqFM8JxciA42dFqNKgl4S08BWLw QYbxCIkVDcmITyR3+X82ngpNk6KYTJN0bqsVCire02/8IeDqIBXP/9L2DvFHYzAySpZC jK/g==
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=6TFn5UsPaFw5NkvR0Clh1WjzdmcVyuknQ2AwIqdZHbU=; b=KLwExS3T5klxPltzjbpjS2OGigHdZXknnjptg/mdBVlFJRntPExobu6/Mw+IK/mtKW GqFkExtcMz0t3PnM9lOblQNs5yRaDlJZCutCoZzbn+W96wmgJg0nhZ1U/CzSLSQqH+vZ Jmh5cCsHNprvi1u4PT3DprLrQdhRtK/HX9fhjDf8Iga+IU9KzDUmRYG1yvVvWfUu3t/I /BQjadltXlCNR/xuAz+rBaH7c8z3dgKAxaHRk88BOJCscpsE9ggJX1b8w+Qs/Mav7B74 Xx14f5dProZUe1Kcqo1QIK4jUoqpfqWOzbPBloSh686fWsDRr6EAJ7j+yH6gQK2WrN91 aBkw==
X-Gm-Message-State AD7BkJL2pg/12SQEj/1ZjUuJJMy0ap8lc+Nd8HstjqQz5iwKgHKls5kYP0qYlD6B9Cw+YqOles+k+U451FTaGw==
X-Received by 10.50.112.10 with SMTP id im10mr12959850igb.93.1457366593186; Mon, 07 Mar 2016 08:03:13 -0800 (PST)
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:104218

Show key headers only | View raw


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


Thread

Re: importing Ian Kelly <ian.g.kelly@gmail.com> - 2016-03-07 09:02 -0700

csiph-web