import bug

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Tue Nov 3 18:26:18 EST 2009


En Tue, 03 Nov 2009 12:29:10 -0300, Ask Solem <asksolem at gmail.com>  
escribió:

> If you have a module named myapp.django, and someone writes a cool
> library called
> django that you want to use, you can't use it unless you rename your
> local django module.
>
>
> file myapp/django.py:
>
>     from django.utils.functional import curry
>
> ImportError: No module named utils.functional
>
> At least that's what I get, maybe there is some workaround, some way
> to say this is an absolute path?

Yes, that's exactly the way to solve it. Either move on to Python 3, or  
use:
 from __future__ import absolute_import

When absolute imports are in effect, and assuming your code is inside a  
package, then neither "import re" nor "from django.utils.functional import  
curry" are affected by your own module names, because those statements  
imply an absolute import ("absolute" means that the module is searched  
along sys.path).
The only way to import a local file "re.py" is using "from .re import  
something"; the leading dot means it's a relative import ("relative" means  
that the module is searched in a single directory: the current package  
directory and its parents, depending on how many dots are specified)

-- 
Gabriel Genellina




More information about the Python-list mailing list