Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #104220
| Path | csiph.com!eternal-september.org!feeder.eternal-september.org!newsfeed.kamp.net!newsfeed.kamp.net!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: importing |
| Date | Tue, 8 Mar 2016 03:08:04 +1100 |
| Lines | 43 |
| Message-ID | <mailman.22.1457366891.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 eTSgSqBM6zrcRNKb3ngesgXucQ49MiWsfvBJNC/lQ/Xg== |
| Return-Path | <rosuav@gmail.com> |
| 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; 'received:209.85.223': 0.03; 'prefix': 0.07; 'cc:addr:python-list': 0.09; 'imported.': 0.09; 'imports': 0.09; 'modulo': 0.09; 'prefixed': 0.09; 'syntax': 0.13; 'ignore': 0.14; 'packages.': 0.15; '"*"': 0.16; '2016': 0.16; 'different,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'modules,': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'tk()': 0.16; 'wrote:': 0.16; 'attribute': 0.18; 'module,': 0.18; 'nested': 0.18; 'typing': 0.18; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'space.': 0.22; 'tkinter': 0.22; 'am,': 0.23; 'errors': 0.23; 'references': 0.23; 'slightly': 0.23; 'this:': 0.23; 'import': 0.24; 'header:In-Reply- To:1': 0.24; 'module': 0.25; 'van': 0.26; 'message- id:@mail.gmail.com': 0.27; 'errors.': 0.27; 'module.': 0.27; 'package.': 0.27; "skip:' 10": 0.28; 'implied': 0.29; 'loads': 0.29; 'that.': 0.30; 'work.': 0.30; 'somebody': 0.30; 'guess': 0.31; '[1]': 0.32; 'case,': 0.34; 'recommended': 0.34; 'tue,': 0.34; 'list': 0.34; 'received:google.com': 0.35; 'done': 0.35; 'star': 0.35; 'something': 0.35; 'but': 0.36; 'should': 0.36; 'received:209.85': 0.36; 'loaded': 0.36; 'modules': 0.36; 'subject:: ': 0.37; 'thought': 0.37; "won't": 0.38; 'received:209': 0.38; 'names': 0.38; 'anything': 0.38; 'means': 0.39; 'well.': 0.40; 'still': 0.40; 'space': 0.40; 'some': 0.40; 'your': 0.60; 'skip:u 10': 0.61; 'mar': 0.65; 'obvious': 0.76; 'chrisa': 0.84; 'definitive': 0.84; 'to:none': 0.91; '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:date:message-id:subject:from:cc; bh=xfEEQH+7PHZ2SMG60X/ArNvGKLnNfhoBUdLtGTq6YmA=; b=VLegdAbN12JYKxmaAEsiS3Z6nvE/pyj8VZiw+pF+2cpPAiQYK+HTw4qWh+nBJHmZEd ORDbNxYI5/MKjnGWvwnPyLVliRW+elCkA6ZDeIuzKDR1CbGxZCARcgecQV7UQrow8COy Jp4hEL/TT/cQmQcRo+DYcqAv866/K9B/zzBwR6rj9wO08ZmOyIH+WCR8wlcBULbanjvo nMDiWNu1y/dKa2uKISQHbvMvsRL6rEMb19TCacw98DpqElTvnwZIbYTxeUfdtx0i4c7F 6lcJU+RbDrz5saQ9c6+314L2WsaqLRXdimvOakAaPZFx7SeS2uefATSDmtCSojF8NTj1 v7Ow== |
| 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:date :message-id:subject:from:cc; bh=xfEEQH+7PHZ2SMG60X/ArNvGKLnNfhoBUdLtGTq6YmA=; b=nFh4/TTHik6dqZkVGaJbM9Y02VLYMh2fvUJd7umOiHxLowJRjd6XD04jge6CMkrrHL 06ORnxCTZc5XMtQCsYALifEgARS49rA7tPc2m1GQAi4uOvCPUZehbrvHnXQY+uaD07+z 8Fk5RyDmHu8Q27u6UlEjKLXhNyPGgzoKuqBo/33S6z1EzU64uZ4CV9yXvAzmcckhjAoR kMcG11Cx3yjJXhl5iQYwnHIEMf3/M3JNBsGmt1FqhChfAINa03LhZ6LeKi1ndx7Lc3Um YRiAkCvyvefe7mowSsK5HoEGud3Va5MCHInCnkpEeORN9xqIQrx94YVZKNOn1/GBBcej 8LzA== |
| X-Gm-Message-State | AD7BkJK91HkLS3uhFgD4Avv2/WqqG9QkVqgzehMbOmYWJfZqoeTnrEE18TYgsujUcd9W8mxkSyv2qWcXnSNDjQ== |
| X-Received | by 10.107.158.20 with SMTP id h20mr21303416ioe.31.1457366884578; Mon, 07 Mar 2016 08:08:04 -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:104220 |
Show key headers only | View raw
On Tue, Mar 8, 2016 at 2: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'" Your description is of a general module, but tkinter is actually a package. Packages are slightly different, in that their modules might not be loaded automatically. You can also do this: import tkinter.messagebox which is a syntax that works ONLY with packages. [1] > 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. > > 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? Sorta-kinda. The star import means "load all the obvious names". Even with non-package modules, it won't always import everything - if there's a list of names in __all__, only those names will be imported. Generally, this means you don't get nested module references (eg because a module did "import sys"), but it can do anything else as well. The documentation should tell you what you need to import to make something work. In this case, I would guess that "import tkinter.messagebox" or "from tkinter import messagebox" would be the recommended way to use this module. ChrisA [1] Modulo os.path, which is done by injection. Ignore that.
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: importing Chris Angelico <rosuav@gmail.com> - 2016-03-08 03:08 +1100
csiph-web