I have recently switched from python 2.7 to python 3.2
considering following folder structure:
~/my_program
~/my_program/modules
where *my_program* is the root of the application, containing main script called main.py
*my_program/modules* is used to store all additional classes and subscripts
in python2.x I was able to import any file “module” the same way I do import standard modules
from modules import abc.py
however, while I try to launch the same program in python3.2 I get the error message saying:
File "/my_program/modules/__init__.py" line 1
import abc, def
ImportError: No module named abc
Please advise
It’s a good example you are using, because “abc” is in fact a module in the standard library. So in fact, if you in Python 3 do
import abcthat will work just fine, but you will get the standard library module.In Python 2, if you had a local module called abc.py, that
import abcwould import the local module instead. That means you couldn’t import the module from the standard library.In Python 3, this has been changed, and you now need to use the fully qualified name, in your case probably
from modules import abc.