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: 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: 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:105199 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 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...