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


Groups > comp.lang.python > #105199

Re: submodules

Path csiph.com!feeder.erje.net!2.eu.feeder.erje.net!newsfeed0.kamp.net!newsfeed.kamp.net!fu-berlin.de!uni-berlin.de!not-for-mail
From Peter Otten <__peter__@web.de>
Newsgroups comp.lang.python
Subject Re: submodules
Date Fri, 18 Mar 2016 12:03:25 +0100
Organization None
Lines 53
Message-ID <mailman.312.1458299016.12893.python-list@python.org> (permalink)
References <56ebdb83$0$3330$426a74cc@news.free.fr>
Mime-Version 1.0
Content-Type text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding 7Bit
X-Trace news.uni-berlin.de WCrGRN5x6sGhIybStL4RWgKkh3FfaX2weKjemCR4HgJw==
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'root': 0.04; 'python3': 0.05; 'ast': 0.09; 'explicitely': 0.09; 'imported': 0.09; 'modules.': 0.09; 'namespace': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'importing': 0.15; '(name,': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'received:t-ipconnect.de': 0.16; 'tk()': 0.16; 'wrote:': 0.16; 'basically': 0.18; 'variable': 0.18; '>>>': 0.20; 'tkinter': 0.22; 'import': 0.24; 'header:User-Agent:1': 0.26; "doesn't": 0.26; 'header:X-Complaints-To:1': 0.26; 'value)': 0.29; "i'd": 0.31; 'candidate': 0.31; 'but': 0.36; 'there': 0.36; '(and': 0.36; 'depends': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'skip:v 20': 0.38; 'means': 0.39; 'why': 0.39; 'to:addr:python.org': 0.40; 'received:de': 0.40; 'your': 0.60; 'avoid': 0.61; 'personally': 0.61; 'tkinter,': 0.84; 'ttk': 0.84; 'inefficient': 0.91
X-Injected-Via-Gmane http://gmane.org/
X-Gmane-NNTP-Posting-Host p57bd8b3b.dip0.t-ipconnect.de
User-Agent KNode/4.13.3
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:105199

Show key headers only | View raw


ast wrote:

> Hello
> 
> Since in python3 ttk is a submodule of tkinter, I was expecting this
> to work:
> 
> from tkinter import *
> 
> root = Tk()
> nb = ttk.Notebook(root)
> 
> but it doesnt, ttk is not known.
> 
> I have to explicitely import ttk with
> 
> from tkinter import ttk
> 
> why ?

If there's no tkinter.__all__

from tkinter import *

is basically

import tkinter
globals().update(
 (name, value) for name, value in 
 vars(tkinter).items() if not name.startswith("_")
)
del tkinter

so if "from tkinter import *" doesn't inject ttk in your namespace this 
means that there is no variable tkinter.ttk. This is because there is no

from . import ttk

in tkinter/__init__.py, and automagically importing all candidate submodules 
is inefficient (and unsafe).

However, once you import tkinter.ttk the name is added

>>> import tkinter.ttk
>>> from tkinter import *
>>> ttk
<module 'tkinter.ttk' from '/usr/lib/python3.4/tkinter/ttk.py'>

so what you get with the *-import depends on what has been imported before, 
perhaps by other modules. 

Personally I'd avoid the *-import altogether...

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


Thread

submodules "ast" <nomail@com.invalid> - 2016-03-18 11:42 +0100
  Re: submodules Peter Otten <__peter__@web.de> - 2016-03-18 12:03 +0100
    Re: submodules "ast" <nomail@com.invalid> - 2016-03-18 13:44 +0100

csiph-web