Fix for problem importing modules in packages in Pymacs.py (0.12)
Syver Enstad
syver-en+usenet at online.no
Tue Jan 1 03:42:22 EST 2002
The point being recursing to the "lowest" level to get the actual
module.
This fixes the problem I was having with importing modules like
Emacs.extensions.
>From pymacs.py, first is new code, second is original 0.12 version
***************
*** 168,183 ****
try:
if directory:
sys.path.insert(0, directory)
! # if the module_name is of the form package.module
! # then the return value of __import__ is the package not the module
! def my_import(name): # fix copied from the python library documentation
! mod = __import__(name)
! components = '.'.split(name)
! for comp in components[1:]:
! mod = getattr(mod, comp) # get the next package or module
! return mod
! object = my_import(module_name)
!
finally:
if directory:
del sys.path[0]
--- 168,174 ----
try:
if directory:
sys.path.insert(0, directory)
! object = __import__(module_name)
finally:
if directory:
del sys.path[0]
--
Vennlig hilsen
Syver Enstad
More information about the Python-list
mailing list