Nested module and package imports in Python -
we have large python project (200+ files)
and till i've been handling dependencies there few spots new part of project used , existing part module , it's been simple enough make sure imports in right order.
but i'm getting trouble when module in sub-package requires module form sub-package
to illustrate take simplified version
the file system
core |__init__.py |database -|__init__.py -|dialogs --|__init__.py --|somedialog.py -|controls --|__init__.py --|somecontrol.py |frame.py now if in somecontrol.py import somedialog.py via statement from core.dialogs.somedialog import somedialog somedialog class in file somedialog
when go import core in main application error "core" has no module "database"
how can fix this?
this case names "circular imports". can import modules in functions , methods need use them.
# somedialog.py class dialog(object): def draw(self): ..controls.somecontrol import control control() # somecontrol.py def control(): ..dialogs.somedialog import all_dialogs do_something(all_dialogs)
Comments
Post a Comment