Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b2c729f

Browse files
committed
Extended IDLE's open module menu item to handle hierarchical module names.
Will look at doing something similar in import.c so that the effort won't have to be repeated elsewhere. Closes SF patch 600152.
1 parent d750036 commit b2c729f

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

Tools/idle/EditorWindow.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,20 @@
8181
by Guido van Rossum
8282
""" % idlever.IDLE_VERSION
8383

84+
def _find_module(fullname, path=None):
85+
"""Version of imp.find_module() that handles hierarchical module names"""
86+
87+
file = None
88+
for tgt in fullname.split('.'):
89+
if file is not None:
90+
file.close() # close intermediate files
91+
(file, filename, descr) = imp.find_module(tgt, path)
92+
if descr[2] == imp.PY_SOURCE:
93+
break # find but not load the source file
94+
module = imp.load_module(tgt, file, filename, descr)
95+
path = module.__path__
96+
return file, filename, descr
97+
8498
class EditorWindow:
8599

86100
from Percolator import Percolator
@@ -340,10 +354,9 @@ def open_module(self, event=None):
340354
name = string.strip(name)
341355
if not name:
342356
return
343-
# XXX Ought to support package syntax
344357
# XXX Ought to insert current file's directory in front of path
345358
try:
346-
(f, file, (suffix, mode, type)) = imp.find_module(name)
359+
(f, file, (suffix, mode, type)) = _find_module(name)
347360
except (NameError, ImportError), msg:
348361
tkMessageBox.showerror("Import error", str(msg), parent=self.text)
349362
return

0 commit comments

Comments
 (0)