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

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -