create Python package and import modules

2019-08-03 18:45发布

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条回答
Emotional °昔
2楼-- · 2019-08-03 18:55

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.

查看更多
登录 后发表回答