[Python-Dev] Fix import errors to have data
Jim Fulton
jim at zope.com
Tue Jul 27 19:57:50 CEST 2004
Phillip J. Eby wrote:
> At 01:45 PM 7/27/04 -0400, Jim Fulton wrote:
>
>> Barry Warsaw wrote:
>>
>>> On Tue, 2004-07-27 at 13:25, Tim Peters wrote:
>>>
>>>> Sure! Jim wants to distinguish "absenceness" from "brokenness" for
>>>> some reason.
>>>
>>>
>>> So, why doesn't imp.find_module() fit the bill?
>>
>>
>> It doesn't handle packages.
>>
>> >>> import compiler.ast
>> >>> import imp
>> >>> imp.find_module('compiler.ast')
>> Traceback (most recent call last):
>> File "<stdin>", line 1, in ?
>> ImportError: No module named compiler.ast
>
>
> Sure it does; you just have to ask it nicely: :)
>
> Python 2.2.2 (#37, Oct 14 2002, 17:02:34) [MSC 32 bit (Intel)] on win32
> Type "copyright", "credits" or "license" for more information.
> IDLE 0.8 -- press F1 for help
> >>> import imp
> >>> imp.find_module('compiler')
> (None, 'C:\\PYTHON22\\lib\\compiler', ('', '', 5))
> >>> import compiler
> >>> imp.find_module('ast',compiler.__path__)
> (<open file 'C:\PYTHON22\lib\compiler\ast.py', mode 'r' at 0x00A99660>,
> 'C:\\PYTHON22\\lib\\compiler\\ast.py', ('.py', 'r', 1))
> >>>
Right. That's not exactly the API I had in mind though.
You could certainly create a usable API on top of find_module.
Jim
--
Jim Fulton mailto:jim at zope.com Python Powered!
CTO (540) 361-1714 http://www.python.org
Zope Corporation http://www.zope.com http://www.zope.org
More information about the Python-Dev
mailing list