python module imports issue -
here's picture of directory structure:
parts.py machine/ __init__.py parts.py
i have directory (a package) called machine
in there __init__.py , parts.py
at same level machine, there file named parts.py
in parts.py, code looks this:
#parts.py class parts(object): pass
in machine.parts code looks this
#machine.parts parts import parts class machineparts(parts): pass
when try import machine.parts, import error. don't want change directory structure. how should fix , retain pep8 style?
you should make package adding top-level __init__.py
, giving meaningful name top-level directory:
mypackage __init__.py parts.py machine/ __init__.py parts.py
then, use absolute imports:
#machine.parts mypackage.parts import parts class machineparts(parts): pass
Comments
Post a Comment