From: guido at eric.cnri.reston.va.us (Guido van Rossum)
Date: 23 Apr 1999 09:45:47 -0400
Subject: Running idle as a package
References: <372050E3.9D05CE8F@easics.be>
Message-ID: <5lr9pbsb5g.fsf@eric.cnri.reston.va.us>
Content-Length: 1644
X-UID: 178                                                  

Jan Decaluwe <jand at easics.be> writes:

> I was trying to run idle as a package, so I turned the idle
> directory into a python package. But then I got:
> 
>   Python 1.5.2 (#2, Apr 21 1999, 17:14:19)  [GCC 2.8.1] on sunos5
>   Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>   >>> from idle import idle
>   Failed to load extension 'SearchBinding'
>   Traceback (innermost last):
>     File "/usr/local/lib/python1.5/site-packages/idle/EditorWindow.py", line 470, in
> load_standard_extensions
>       self.load_extension(name)
>     File "/usr/local/lib/python1.5/site-packages/idle/EditorWindow.py", line 481, in load_extension
>       mod = __import__(name)
>   ImportError: No module named SearchBinding
>   ...
> 
> Apparently the problem is caused by the call to __import__,
> that is not aware of the intra-package shortcut.

Thanks.  A better fix (that works whether or not idle is being used as
a package) is to change the __import__ call as follows (line numbers
may be off):

*** EditorWindow.py	1999/04/20 15:45:28	1.18
--- EditorWindow.py	1999/04/23 13:42:38
***************
*** 484,490 ****
          return extend.standard
  
      def load_extension(self, name):
!         mod = __import__(name)
          cls = getattr(mod, name)
          ins = cls(self)
          self.extensions[name] = ins
--- 484,490 ----
          return extend.standard
  
      def load_extension(self, name):
!         mod = __import__(name, globals(), locals(), [])
          cls = getattr(mod, name)
          ins = cls(self)
          self.extensions[name] = ins

--Guido van Rossum (home page: http://www.python.org/~guido/)




