python import error

Michael Torrie torriem at gmail.com
Tue Dec 10 23:25:50 EST 2013


On 12/10/2013 08:56 PM, smilesonisamal at gmail.com wrote:
> Traceback (most recent call last):
>   File "aaa.py", line 5, in <module>
>     from ccc.ddd import sss
> ImportError: No module named ccc.ddd
> 
> directory structure as follows:
> 
> ccc
> |
>  ddd
>    |
>     aaa.py
>     sss.py

This is because directories have no inherent meaning to python.  A
module is normally a file.  If you want to group a bunch of files
together you have to use a package. See the docs on how to make a
package.  But the namespace structure within a package isn't based on
the directory tree either.  It's usually set up by __init__.py within
the package which imports modules defined in the package into the
namespace.

http://docs.python.org/3/tutorial/modules.html#packages

Hope this helps.




More information about the Python-list mailing list