What benefits or disadvantages would importing a module that contains 'import' commands?

前端 未结 2 489
野趣味
野趣味 2021-01-22 07:31

If I were to create a module that was called for example imp_mod.py and inside it contained all (subjectively used) relevant modules that I frequently used.

2条回答
  •  春和景丽
    2021-01-22 07:48

    As lucasnadalutti mentioned, you can access them by importing your module.

    In terms of advantages, it can make your main program care less about where the imports are coming from if the imp_mod handles all imports, however, as your program gets more complex and starts to include more namespaces, this approach can get more messy. You can start to handle a bit of this by using __init__.py within directories to handle imports to do a similar thing, but as things get more complex, personally, I feel it add a little more complexity. I'd rather just know where a module came from to look it up.

提交回复
热议问题