Python : import module once for a whole package
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm currently coding an app which is basically structured that way : main.py + Package1 +--- Class1.py +--- Apps + Package2 +--- Class1.py +--- Apps So I have two questions : First, inside both packages, there are modules needed by all Apps, eg : re. Is there a way I can import a module for the whole package at once, instead of importing it in every file that needs it ? And, as you can see, Class1 is used in both packages. Is there a good way to share it between both packages to avoid code duplication ? 回答1: I would strongly recommend