This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author terry.reedy
Recipients Dave Peck, Trundle, brett.cannon, docs@python, terry.reedy
Date 2011-04-01.23:39:28
SpamBayes Score 5.386532e-10
Marked as misclassified No
Message-id <1301701169.01.0.138798729959.issue11676@psf.upfronthosting.co.za>
In-reply-to
Content
I verified this for 3.2 (and IDLE) with

import sys, tkinter
"ttk" in dir(sys.modules['tkinter']) # False
import tkinter.ttk
"ttk" in dir(sys.modules['tkinter']) # True

====reload========

import sys,imp
imp.load_module('tkinter',*imp.find_module('tkinter'))
imp.load_module('tkinter.ttk',*imp.find_module('ttk',
  sys.modules["tkinter"].__path__))
"ttk" in dir(sys.modules['tkinter']) # False
from tkinter import ttk # ImportError

Given that 'ttk' is only added to the tkinter entry when ttk is imported via tkinter, I am not surprised that the direct import with imp fails to affect the tkinter entry. Imp would have to notice that ttk is in a directory with __init__, get the name of the parent directory, and then check to see whether or not that parent had already been imported. Unlike import

import ttk #fails

imp does not require such a previous import:

imp.load_module('ttk',*imp.find_module('ttk',
 ["C:/programs/python32/Lib/tkinter"]))

succeeds, which shows again that import and imp act differently.

Dave, can you suggest added text and a location to put it?

Hmmm. How about after "If the load ...", add "A successful load does not affect previously loaded package modules as this function operates independently of package structure."
History
Date User Action Args
2011-04-01 23:39:29terry.reedysetrecipients: + terry.reedy, brett.cannon, Trundle, docs@python, Dave Peck
2011-04-01 23:39:29terry.reedysetmessageid: <1301701169.01.0.138798729959.issue11676@psf.upfronthosting.co.za>
2011-04-01 23:39:28terry.reedylinkissue11676 messages
2011-04-01 23:39:28terry.reedycreate