Import question

Andrew Degtiariov andrew.degtiariov at gmail.com
Mon Feb 8 04:37:53 EST 2010


2010/2/6 Gabriel Genellina <gagsl-py2 at yahoo.com.ar>

> En Fri, 05 Feb 2010 13:21:47 -0300, Andrew Degtiariov
> <andrew.degtiariov at gmail.com> escribió:
>
>
>  Code of our project has split into several packages and we deploy the
>> project using buildout.
>> All worked fine until I need to dynamically inspect python modules.
>>
>
> Entirely by luck, I'd say :)
>
>
>  ├───project.api.config
>> │   ├───project
>> │   │   └───api
>> │   │       └───config
>> │   │           └───settings
>> │   └───project.api.config.egg-info
>> ├───project.api.contacts
>> │   ├───project
>> │   │   └───api
>> │   │       └───contacts
>> │   │           ├───importer
>> │   │           └───views
>> │   └───project.api.contacts.egg-info
>>
>
>  Regular code like "import project.api.config" worked fine, but now I'm
>> tryed
>> __import__('project.api.config'):
>>
>> $ bin/python
>>
>>  import project.api.config
>>>>> __import__('project.api.config')
>>>>>
>>>> <module 'project from
>> 'c:\users\ad\project\src\project.api.contacts\project\__init__.pyc'>
>>
>
>
>
If someone is interesting - __import__ works but imp doesn't.
In my example:
>>> m = __import__('project.api.config')
>>> m
<module 'project from
'c:\users\ad\project\src\project.api.contacts\project\__init__.pyc'>
>>> m.api
<module 'project.api from
'c:\users\ad\project\src\project.api.contacts\project\api\__init__.pyc'>
>>> m.api.config
<module 'project.api.config'
from'c:\users\ad\project\src\project.api.config\project\api\config\__init__.pyc'>

Please note that the m and m.api pointed to first installing package with
namespace project.api but m.api.config have pointed to the proper file.

And releasing code with several distributions it is one of goals of
Distribute. And you might look to pypi for... zope. There is lot of package
which names starts from "zope."
It's really convenient

-- 
Andrew Degtiariov
DA-RIPE
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100208/9e006d28/attachment.html>


More information about the Python-list mailing list