create Python package and import modules

扶醉桌前 提交于 2020-01-15 11:16:50

问题


I'm trying to write my first Python package, and almost all my modules will need to use NumPy. Should I write import numpy in every single module or is there some place in the package I can just import it once so every module can use it? What's the best way to do this?


回答1:


Yes, just import it everywhere it's needed.

Don't get too clever with writing functions that import everything for you or metamodules that import things and from which you import *; all of that only serves to make your code hard to read and is just another place for bugs to happen.



来源:https://stackoverflow.com/questions/15259639/create-python-package-and-import-modules

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!